local-in-30s / src /utils /speech.ts
Jacky G
Deploy: gr.Server + React SPA + /api/decode (PNGs via hf CLI)
a8f2679
Raw
History Blame Contribute Delete
650 Bytes
export function canSpeak() {
return typeof window !== 'undefined' && 'speechSynthesis' in window && 'SpeechSynthesisUtterance' in window;
}
export function stopSpeaking() {
if (!canSpeak()) return;
window.speechSynthesis.cancel();
}
export function speakGuideText(text: string, onEnd: () => void) {
if (!canSpeak()) return false;
window.speechSynthesis.cancel();
const utterance = new SpeechSynthesisUtterance(text);
utterance.rate = 0.92;
utterance.pitch = 1;
utterance.volume = 1;
utterance.lang = 'en-US';
utterance.onend = onEnd;
utterance.onerror = onEnd;
window.speechSynthesis.speak(utterance);
return true;
}