mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-13 19:20:04 +00:00
4fa2ef410f
* ✨ feat(tts): Add tts and stt basic features * ✨ feat(tts): Handle error * 💄 style(tts): Add alert to error handler * 🐛 fix(tts): Error display * ♻️ refactor: refactor the openai initial code to the createBizOpenAI * ♻️ refactor(tts): Refactor header config * ✨ feat: Add TTS voice preview * 🐛 fix(tts): Fix header * 🐛 fix: Fix api --------- Co-authored-by: Arvin Xu <arvinx@foxmail.com>
30 lines
974 B
TypeScript
30 lines
974 B
TypeScript
import { OpenAISTTPayload } from '@lobehub/tts';
|
|
import { createOpenaiAudioTranscriptions } from '@lobehub/tts/server';
|
|
|
|
import { createBizOpenAI } from '../createBizOpenAI';
|
|
|
|
export const runtime = 'edge';
|
|
|
|
export const POST = async (req: Request) => {
|
|
const formData = await req.formData();
|
|
const speechBlob = formData.get('speech') as Blob;
|
|
const optionsString = formData.get('options') as string;
|
|
const payload = {
|
|
options: JSON.parse(optionsString),
|
|
speech: speechBlob,
|
|
} as OpenAISTTPayload;
|
|
|
|
const openaiOrErrResponse = createBizOpenAI(req, payload.options.model);
|
|
|
|
// if resOrOpenAI is a Response, it means there is an error,just return it
|
|
if (openaiOrErrResponse instanceof Response) return openaiOrErrResponse;
|
|
|
|
const res = await createOpenaiAudioTranscriptions({ openai: openaiOrErrResponse, payload });
|
|
|
|
return new Response(JSON.stringify(res), {
|
|
headers: {
|
|
'content-type': 'application/json;charset=UTF-8',
|
|
},
|
|
});
|
|
};
|