diff --git a/backend/apps/audio/main.py b/backend/apps/audio/main.py index 699d3b9ad..663e20c97 100644 --- a/backend/apps/audio/main.py +++ b/backend/apps/audio/main.py @@ -199,6 +199,14 @@ async def speech(request: Request, user=Depends(get_verified_user)): headers["Authorization"] = f"Bearer {app.state.config.TTS_OPENAI_API_KEY}" headers["Content-Type"] = "application/json" + try: + body = body.decode("utf-8") + body = json.loads(body) + body["model"] = app.state.config.TTS_MODEL + body = json.dumps(body).encode("utf-8") + except Exception as e: + pass + r = None try: r = requests.post( diff --git a/src/lib/apis/audio/index.ts b/src/lib/apis/audio/index.ts index 7bd8981fe..9716c552a 100644 --- a/src/lib/apis/audio/index.ts +++ b/src/lib/apis/audio/index.ts @@ -98,7 +98,7 @@ export const synthesizeOpenAISpeech = async ( token: string = '', speaker: string = 'alloy', text: string = '', - model: string = 'tts-1' + model?: string ) => { let error = null; @@ -109,9 +109,9 @@ export const synthesizeOpenAISpeech = async ( 'Content-Type': 'application/json' }, body: JSON.stringify({ - model: model, input: text, - voice: speaker + voice: speaker, + ...(model && { model }) }) }) .then(async (res) => { diff --git a/src/lib/components/chat/MessageInput/CallOverlay.svelte b/src/lib/components/chat/MessageInput/CallOverlay.svelte index 25c68a1e3..f35f320ab 100644 --- a/src/lib/components/chat/MessageInput/CallOverlay.svelte +++ b/src/lib/components/chat/MessageInput/CallOverlay.svelte @@ -170,8 +170,7 @@ const res = await synthesizeOpenAISpeech( localStorage.token, $settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice, - text, - $settings?.audio?.tts?.model ?? $config?.audio?.tts?.model + text ).catch((error) => { toast.error(error); assistantSpeaking = false; @@ -267,8 +266,7 @@ const res = await synthesizeOpenAISpeech( localStorage.token, $settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice, - sentence, - $settings?.audio?.tts?.model ?? $config?.audio?.tts?.model + sentence ).catch((error) => { toast.error(error); diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 11eaa754d..8c9ac7b4c 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -245,8 +245,7 @@ const res = await synthesizeOpenAISpeech( localStorage.token, $settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice, - sentence, - $settings?.audio?.tts?.model ?? $config?.audio?.tts?.model + sentence ).catch((error) => { toast.error(error);