Auto-update: Thu Aug 8 06:28:18 PDT 2024
This commit is contained in:
parent
da80656c36
commit
5a03b3af0e
1 changed files with 17 additions and 13 deletions
|
@ -147,7 +147,6 @@ async def generate_speech(
|
||||||
|
|
||||||
if model == "eleven_turbo_v2":
|
if model == "eleven_turbo_v2":
|
||||||
info("Using ElevenLabs.")
|
info("Using ElevenLabs.")
|
||||||
voice = await determine_voice_id(voice)
|
|
||||||
audio_file_path = await elevenlabs_tts(model, text, voice, title, output_dir)
|
audio_file_path = await elevenlabs_tts(model, text, voice, title, output_dir)
|
||||||
else: # if model == "xtts":
|
else: # if model == "xtts":
|
||||||
info("Using XTTS2")
|
info("Using XTTS2")
|
||||||
|
@ -233,6 +232,7 @@ async def elevenlabs_tts(model: str, input_text: str, voice: str, title: str = N
|
||||||
"model_id": model
|
"model_id": model
|
||||||
}
|
}
|
||||||
headers = {"Content-Type": "application/json", "xi-api-key": ELEVENLABS_API_KEY}
|
headers = {"Content-Type": "application/json", "xi-api-key": ELEVENLABS_API_KEY}
|
||||||
|
try:
|
||||||
async with httpx.AsyncClient(timeout=httpx.Timeout(300.0)) as client: # 5 minutes timeout
|
async with httpx.AsyncClient(timeout=httpx.Timeout(300.0)) as client: # 5 minutes timeout
|
||||||
response = await client.post(url, json=payload, headers=headers)
|
response = await client.post(url, json=payload, headers=headers)
|
||||||
output_dir = output_dir if output_dir else TTS_OUTPUT_DIR
|
output_dir = output_dir if output_dir else TTS_OUTPUT_DIR
|
||||||
|
@ -242,9 +242,13 @@ async def elevenlabs_tts(model: str, input_text: str, voice: str, title: str = N
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
with open(file_path, "wb") as audio_file:
|
with open(file_path, "wb") as audio_file:
|
||||||
audio_file.write(response.content)
|
audio_file.write(response.content)
|
||||||
|
info(f"file_path: {file_path}")
|
||||||
return file_path
|
return file_path
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=response.status_code, detail="Error from ElevenLabs API")
|
raise HTTPException(status_code=response.status_code, detail="Error from ElevenLabs API")
|
||||||
|
except Exception as e:
|
||||||
|
err(f"Error from Elevenlabs API: {e}")
|
||||||
|
raise HTTPException(status_code=response.status_code, detail="Error from ElevenLabs API")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue