diff --git a/app/components/ltt.ts b/app/components/ltt.ts index 266853a9c8e..ef00051d69e 100644 --- a/app/components/ltt.ts +++ b/app/components/ltt.ts @@ -2,23 +2,25 @@ import * as sdk from "microsoft-cognitiveservices-speech-sdk"; import { getServerSideConfig } from "@/app/config/server"; const config = getServerSideConfig(); -let subscriptionKey = config.azurekey; +let subscriptionKey = config.baseUrl; const serviceRegion = "eastus"; // 例如 "westus" -if (typeof subscriptionKey !== "string") { - throw new Error("The SUBSCRIPTION_KEY environment variable is not set."); -} +// if (typeof subscriptionKey !== "string") { +// console.error("The subscriptionKey is not a string."+ subscriptionKey); +// throw new Error("The SUBSCRIPTION_KEY environment variable is not set."); +// } // 创建语音识别器 -const speechConfig = sdk.SpeechConfig.fromSubscription( - subscriptionKey, - serviceRegion, -); -// 设置语音识别的语言 -speechConfig.speechRecognitionLanguage = "zh-CN"; +export default function recognizeSpeech(): Promise { + let subscriptionKey = process.env.OPENAI_ORG_ID; + const speechConfig = sdk.SpeechConfig.fromSubscription( + subscriptionKey, + serviceRegion, + ); -const audioConfig = sdk.AudioConfig.fromDefaultMicrophoneInput(); + // 设置语音识别的语言 + speechConfig.speechRecognitionLanguage = "zh-CN"; -export default function recognizeSpeech(): Promise { + const audioConfig = sdk.AudioConfig.fromDefaultMicrophoneInput(); return new Promise((resolve, reject) => { const recognizer = new sdk.SpeechRecognizer(speechConfig, audioConfig); console.log("开始语音识别,请说话..."); diff --git a/app/components/tts.ts b/app/components/tts.ts index 6b48e4313c1..650ac503f21 100644 --- a/app/components/tts.ts +++ b/app/components/tts.ts @@ -2,19 +2,18 @@ import * as sdk from "microsoft-cognitiveservices-speech-sdk"; import { getServerSideConfig } from "@/app/config/server"; const config = getServerSideConfig(); -let subscriptionKey = config.azurekey; +let subscriptionKey = config.baseUrl; // 这些信息应该从环境变量或配置文件中获取,不应硬编码在脚本中。 const serviceRegion = "eastus"; // 例如 "westus" -if (typeof subscriptionKey !== "string") { - throw new Error("The SUBSCRIPTION_KEY environment variable is not set."); -} -// 创建语音识别器 -const speechConfig = sdk.SpeechConfig.fromSubscription( - subscriptionKey, - serviceRegion, -); + export default function convertTextToSpeech(text: string) { + let subscriptionKey = process.env.OPENAI_ORG_ID || ""; + // 创建语音识别器 + const speechConfig = sdk.SpeechConfig.fromSubscription( + subscriptionKey, + serviceRegion, + ); return new Promise((resolve, reject) => { speechConfig.speechSynthesisVoiceName = "zh-CN-XiaoshuangNeural"; // 使用 Azure 提供的声音名列表,选择合适的声音 diff --git a/app/config/server.ts b/app/config/server.ts index a66f05681cc..c455d0b7336 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -30,8 +30,6 @@ declare global { // google only GOOGLE_API_KEY?: string; GOOGLE_URL?: string; - - AZURE_SUBSCRIPTION_KEY?: string; } } } @@ -79,7 +77,6 @@ export const getServerSideConfig = () => { return { baseUrl: process.env.BASE_URL, - azurekey: process.env.AZURE_SUBSCRIPTION_KEY ?? "", apiKey, openaiOrgId: process.env.OPENAI_ORG_ID,