mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-12-24 19:28:15 +03:00
15 lines
372 B
JavaScript
15 lines
372 B
JavaScript
export const supportsTTS = 'speechSynthesis' in window;
|
|
|
|
export function speak(text, lang) {
|
|
if (!supportsTTS) return;
|
|
try {
|
|
if (speechSynthesis.speaking) {
|
|
speechSynthesis.cancel();
|
|
}
|
|
const utterance = new SpeechSynthesisUtterance(text);
|
|
if (lang) utterance.lang = lang;
|
|
speechSynthesis.speak(utterance);
|
|
} catch (e) {
|
|
alert(e);
|
|
}
|
|
}
|