Compare commits

..

1 Commits

Author SHA1 Message Date
Evan Wu
01b743aa2e
Merge b73e65d2d0 into 995bef73de 2025-08-10 21:16:19 +00:00

View File

@ -1,5 +1,10 @@
"use client";
import { ApiPath, Alibaba, ALIBABA_BASE_URL } from "@/app/constant";
import {
ApiPath,
Alibaba,
ALIBABA_BASE_URL,
REQUEST_TIMEOUT_MS,
} from "@/app/constant";
import {
useAccessStore,
useAppConfig,
@ -98,9 +103,6 @@ export class QwenApi implements LLMApi {
}
async *streamSpeech(options: SpeechOptions): AsyncGenerator<AudioBuffer> {
if (!options.input || !options.model) {
throw new Error("Missing required parameters: input and model");
}
const requestPayload = {
model: options.model,
input: {
@ -127,7 +129,7 @@ export class QwenApi implements LLMApi {
// make a fetch request
const requestTimeoutId = setTimeout(
() => controller.abort(),
getTimeoutMSByModel(options.model),
REQUEST_TIMEOUT_MS,
);
const res = await fetch(speechPath, speechPayload);
@ -146,20 +148,12 @@ export class QwenApi implements LLMApi {
buffer = lines.pop() || "";
for (const line of lines) {
const data = line.slice(5);
try {
if (line.startsWith("data:")) {
const json = JSON.parse(data);
if (json.output?.audio?.data) {
yield this.PCMBase64ToAudioBuffer(json.output.audio.data);
}
if (line.startsWith("data:")) {
const data = line.slice(5);
const json = JSON.parse(data);
if (json.output?.audio?.data) {
yield this.PCMBase64ToAudioBuffer(json.output.audio.data);
}
} catch (parseError) {
console.warn(
"[StreamSpeech] Failed to parse SSE data:",
parseError,
);
continue;
}
}
}