| 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; | |
| } | |