Last active
October 6, 2023 15:23
-
-
Save gamersindo1223/37a569d94d4f25ac0a74d872a2aaba87 to your computer and use it in GitHub Desktop.
Hugging face anime ai voice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { chromium } from 'playwright-chromium'; | |
const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay)); | |
async function textToSpeech({ text, lang, speed, char, symbolinput }, page) { | |
await page.goto('https://plachta-vits-umamusume-voice-synthesizer.hf.space'); | |
const gradioAppHandle = await page.$('body > gradio-app'); | |
const shadowRoot = await gradioAppHandle.evaluateHandle(node => node.shadowRoot); | |
await shadowRoot.$eval('#tts-input textarea', (el, value) => el.value = value, text); | |
await shadowRoot.$eval('#component-18 input', (el, value) => el.value = value, speed); | |
await shadowRoot.$eval('#component-12 input', (el, value) => el.checked = value, symbolinput); | |
const langSelectHandle = await shadowRoot.$('#component-17 select'); | |
await langSelectHandle.selectOption({ label: lang }); | |
const charSelectHandle = await shadowRoot.$('#component-16 select'); | |
await charSelectHandle.selectOption({ label: char }); | |
await sleep(2000); | |
const textInputValue = await shadowRoot.$eval('#tts-input textarea', el => el.value); | |
if (textInputValue !== text) { | |
throw new Error('Text input value did not update properly'); | |
} | |
await shadowRoot.$eval('#component-24', (el) => el.click()); | |
await page.waitForSelector('audio'); | |
const status = await shadowRoot.$eval('#component-22 textarea', (el) => el.value); | |
const audioUrl = await page.evaluate(() => document.querySelector("body > gradio-app").shadowRoot.querySelector("#tts-audio > audio").src); | |
return { | |
status, | |
audioUrl, | |
}; | |
} | |
const options = { | |
text: 'Hello wrolds', | |
lang: 'English', | |
speed: '1.0', | |
char: '夜兰 Yelan (Genshin Impact)', | |
symbolinput: false, | |
}; | |
(async () => { | |
const browser = await chromium.launch({ headless: false }); | |
const context = await browser.newContext(); | |
const page = await context.newPage(); | |
try { | |
const result = await textToSpeech(options, page); | |
console.log(result.status); | |
console.log(result.audioUrl); | |
} catch (error) { | |
console.error(error); | |
} finally { | |
await browser.close(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment