mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-16 22:13:47 +08:00
修复语音的token获取问题
This commit is contained in:
41
app/api/get_voice_token/route.ts
Normal file
41
app/api/get_voice_token/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
import * as ms_audio_sdk from "microsoft-cognitiveservices-speech-sdk";
|
||||
import { getServerSideConfig } from "@/app/config/server";
|
||||
const serverConfig = getServerSideConfig();
|
||||
// Gets an access token.
|
||||
async function getAccessToken() {
|
||||
let uri = "https://eastasia.api.cognitive.microsoft.com/sts/v1.0/issueToken";
|
||||
let options: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Ocp-Apim-Subscription-Key": serverConfig.azureVoiceKey,
|
||||
},
|
||||
cache: "no-cache",
|
||||
};
|
||||
console.log(options);
|
||||
return await fetch(uri, options);
|
||||
}
|
||||
|
||||
async function handle(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { path: string[] } },
|
||||
) {
|
||||
const get_access_token = await getAccessToken();
|
||||
|
||||
if (!get_access_token.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: "获取access_token失败" },
|
||||
{
|
||||
status: get_access_token.status,
|
||||
statusText: get_access_token.statusText,
|
||||
},
|
||||
);
|
||||
}
|
||||
const access_token = await get_access_token.text();
|
||||
|
||||
return NextResponse.json({ result: access_token });
|
||||
}
|
||||
|
||||
export const GET = handle;
|
||||
// export const POST = handle;
|
||||
Reference in New Issue
Block a user