this repo has no description
at main 15 lines 372 B view raw
1export const supportsTTS = 'speechSynthesis' in window; 2 3export function speak(text, lang) { 4 if (!supportsTTS) return; 5 try { 6 if (speechSynthesis.speaking) { 7 speechSynthesis.cancel(); 8 } 9 const utterance = new SpeechSynthesisUtterance(text); 10 if (lang) utterance.lang = lang; 11 speechSynthesis.speak(utterance); 12 } catch (e) { 13 alert(e); 14 } 15}