@lobehub/tts
Version:
A high-quality & reliable TTS React Hooks library
22 lines (21 loc) • 792 B
JavaScript
//#region src/core/const/polyfill.ts
const getSpeechRecognition = () => {
try {
return globalThis?.SpeechRecognition || window?.SpeechRecognition || window?.webkitSpeechRecognition;
} catch {}
};
const getSpeechSynthesis = () => {
try {
return globalThis?.speechSynthesis || window?.speechSynthesis || window?.webkitSpeechSynthesis;
} catch {}
};
const getSpeechSynthesisUtterance = () => {
try {
return globalThis?.SpeechSynthesisUtterance || window?.SpeechSynthesisUtterance || window?.webkitSpeechSynthesisUtterance;
} catch {}
};
const SpeechRecognition = getSpeechRecognition();
const SpeechSynthesis = getSpeechSynthesis();
const SpeechSynthesisUtterance = getSpeechSynthesisUtterance();
//#endregion
export { SpeechRecognition, SpeechSynthesis, SpeechSynthesisUtterance };