UNPKG

@lobehub/tts

Version:

A high-quality & reliable TTS React Hooks library

28 lines (26 loc) 741 B
import { MicrosoftSpeechTTS } from "../../core/MicrosoftSpeechTTS/index.mjs"; import { useTTS } from "../useTTS/index.mjs"; import { useState } from "react"; //#region src/react/useMicrosoftSpeech/index.ts const useMicrosoftSpeech = (defaultText, init) => { const [text, setText] = useState(defaultText); const { options, locale, api, ...swrConfig } = init; const [response, setResponse] = useState(); return { response, setText, ...useTTS(options.voice, text, async (segmentText) => { const res = await new MicrosoftSpeechTTS({ ...api, locale }).create({ input: segmentText, options }); setResponse(res); return res.arrayBuffer(); }, swrConfig) }; }; //#endregion export { useMicrosoftSpeech };