JavaScript
- 17 ответов
- 0 вопросов
10
Вклад в тег
var voices = window.speechSynthesis.getVoices();
setTimeout(function() { voices = window.speechSynthesis.getVoices(); }, 1000);
function findVoice(lang) {
for (var i = 0; i < voices.length; i++) {
if (voices[i].lang === lang) { return voices[i]; }
}
return null;
}
this.speak = function(s) {
if (!window.speechSynthesis) { return; }
var utterance = new SpeechSynthesisUtterance(s);
utterance.lang = "ru-RU";
utterance.voice = findVoice(utterance.lang);
window.speechSynthesis.speak(utterance);
};