Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
songh3 committed Feb 8, 2024
1 parent ee51284 commit f45f967
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
26 changes: 14 additions & 12 deletions app/components/ltt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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<string> {
const audioConfig = sdk.AudioConfig.fromDefaultMicrophoneInput();
return new Promise<string>((resolve, reject) => {
const recognizer = new sdk.SpeechRecognizer(speechConfig, audioConfig);
console.log("开始语音识别,请说话...");
Expand Down
17 changes: 8 additions & 9 deletions app/components/tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 提供的声音名列表,选择合适的声音

Expand Down
3 changes: 0 additions & 3 deletions app/config/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ declare global {
// google only
GOOGLE_API_KEY?: string;
GOOGLE_URL?: string;

AZURE_SUBSCRIPTION_KEY?: string;
}
}
}
Expand Down Expand Up @@ -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,

Expand Down

0 comments on commit f45f967

Please sign in to comment.