Commit 1f600c2d by DigHuang Committed by GitHub

fix(service): convert web readable stream to node stream in text2Speech (#6985)

parent 19435e58
import type { NextApiResponse } from 'next'; import type { NextApiResponse } from 'next';
import { getAIApi } from '../config'; import { getAIApi } from '../config';
import { getTTSModel } from '../model'; import { getTTSModel } from '../model';
import { Readable } from 'stream';
export async function text2Speech({ export async function text2Speech({
res, res,
...@@ -40,7 +41,11 @@ export async function text2Speech({ ...@@ -40,7 +41,11 @@ export async function text2Speech({
: {} : {}
); );
const readableStream = response.body as unknown as NodeJS.ReadableStream; if (!response.body) {
throw new Error('Response body is empty');
}
const readableStream = Readable.fromWeb(response.body as Parameters<typeof Readable.fromWeb>[0]);
readableStream.pipe(res); readableStream.pipe(res);
const chunks: Uint8Array[] = []; const chunks: Uint8Array[] = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment