Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,393 Bytes
a65e95e 5dfc565 a65e95e 12506f0 a65e95e 5dfc565 a65e95e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import puppeteer from "puppeteer"
import { downloadFileToTmp } from "../utils/downloadFileToTmp.mts"
const instances: string[] = [
process.env.VC_VOICE_GENERATION_SPACE_API_URL
]
// TODO we should use an inference endpoint instead
export async function generateVoice(prompt: string, voiceFileName: string) {
const instance = instances.shift()
instances.push(instance)
console.log("instance:", instance)
const browser = await puppeteer.launch({
headless: false,
protocolTimeout: 800000,
})
const page = await browser.newPage()
await page.goto(instance, {
waitUntil: "networkidle2",
})
await new Promise(r => setTimeout(r, 3000))
const firstTextarea = await page.$('textarea[data-testid="textbox"]')
await firstTextarea.type(prompt)
// console.log("looking for the button to submit")
const submitButton = await page.$("button.lg")
// console.log("clicking on the button")
await submitButton.click()
await page.waitForSelector("audio", {
timeout: 800000, // need to be large enough in case someone else attemps to use our space
})
const voiceRemoteUrl = await page.$$eval("audio", el => el.map(x => x.getAttribute("src"))[0])
console.log({
voiceRemoteUrl,
})
console.log(`- downloading ${voiceFileName} from ${voiceRemoteUrl}`)
await downloadFileToTmp(voiceRemoteUrl, voiceFileName)
return voiceFileName
}
|