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