Auto-update: Thu Aug 8 19:46:30 PDT 2024

This commit is contained in:
sanj 2024-08-08 19:46:30 -07:00
parent 59415fbf9a
commit 4f194eb628

View file

@ -257,12 +257,6 @@ async def determine_voice_id(voice_name: str) -> str:
async def elevenlabs_tts(model: str, input_text: str, voice: str, title: str = None, output_dir: str = None): async def elevenlabs_tts(model: str, input_text: str, voice: str, title: str = None, output_dir: str = None):
# Debug logging
debug(f"API.EXTENSIONS: {API.EXTENSIONS}")
debug(f"API.EXTENSIONS.elevenlabs: {getattr(API.EXTENSIONS, 'elevenlabs', None)}")
debug(f"Tts config: {Tts}")
if getattr(API.EXTENSIONS, 'elevenlabs', False):
voice_id = await determine_voice_id(voice) voice_id = await determine_voice_id(voice)
url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}" url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}"
@ -270,10 +264,10 @@ async def elevenlabs_tts(model: str, input_text: str, voice: str, title: str = N
"text": input_text, "text": input_text,
"model_id": model "model_id": model
} }
# Make sure this is the correct way to access the API key
headers = {"Content-Type": "application/json", "xi-api-key": Tts.elevenlabs.key} headers = {"Content-Type": "application/json", "xi-api-key": Tts.elevenlabs.key}
debug(f"Using ElevenLabs API key: {Tts.elevenlabs.key}")
try: try:
async with httpx.AsyncClient(timeout=httpx.Timeout(300.0)) as client: 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
title = title if title else dt_datetime.now().strftime("%Y%m%d%H%M%S") title = title if title else dt_datetime.now().strftime("%Y%m%d%H%M%S")
@ -284,16 +278,14 @@ async def elevenlabs_tts(model: str, input_text: str, voice: str, title: str = N
audio_file.write(response.content) audio_file.write(response.content)
return file_path return file_path
else: else:
raise HTTPException(status_code=response.status_code, detail="Error from ElevenLabs API") err(f"Error from ElevenLabs API. Status code: {response.status_code}")
err(f"Response content: {response.text}")
raise HTTPException(status_code=response.status_code, detail=f"Error from ElevenLabs API: {response.text}")
except Exception as e: except Exception as e:
err(f"Error from Elevenlabs API: {e}") err(f"Error from Elevenlabs API: {e}")
raise HTTPException(status_code=500, detail=f"Error from ElevenLabs API: {str(e)}") raise HTTPException(status_code=500, detail=f"Error from ElevenLabs API: {str(e)}")
else:
warn(f"elevenlabs_tts called but ElevenLabs module is not enabled in config.")
raise HTTPException(status_code=400, detail="ElevenLabs TTS is not enabled")
async def get_text_content(text: Optional[str], file: Optional[UploadFile]) -> str: async def get_text_content(text: Optional[str], file: Optional[UploadFile]) -> str: