From bfcd0be80f3ae78c0a99667d936ff98187d196cd Mon Sep 17 00:00:00 2001 From: an-lee Date: Wed, 5 Jun 2024 23:29:09 +0800 Subject: [PATCH] Fix OpenAI TTS error when using tts-1-hd (#659) * fix OpenAI TTS error when using tts-1-hd * refactor --- enjoy/src/renderer/hooks/use-conversation.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/enjoy/src/renderer/hooks/use-conversation.tsx b/enjoy/src/renderer/hooks/use-conversation.tsx index b9bbfe9a..8b58dac8 100644 --- a/enjoy/src/renderer/hooks/use-conversation.tsx +++ b/enjoy/src/renderer/hooks/use-conversation.tsx @@ -16,6 +16,7 @@ import OpenAI from "openai"; import { type LLMResult } from "@langchain/core/outputs"; import { v4 } from "uuid"; import * as sdk from "microsoft-cognitiveservices-speech-sdk"; +import { t } from "i18next"; export const useConversation = () => { const { EnjoyApp, webApi, user, apiUrl, learningLanguage } = useContext( @@ -233,7 +234,7 @@ export const useConversation = () => { const { engine, model = "tts-1", voice } = configuration || {}; let buffer; - if (model.startsWith("openai") || model === "tts-1" || model === "tts-2") { + if (model.match(/^(openai|tts-)/)) { buffer = await openaiTTS(params); } else if (model.startsWith("azure")) { buffer = await azureTTS(params); @@ -283,12 +284,12 @@ export const useConversation = () => { maxRetries: 1, }); } else { - throw new Error("OpenAI API key is required"); + throw new Error(t("openaiKeyRequired")); } const file = await client.audio.speech.create({ input: params.text, - model: model.replace("openai-", ""), + model: model.replace("openai/", ""), voice, });