L
L
lexstile2019-06-25 13:16:20
JavaScript
lexstile, 2019-06-25 13:16:20

Why does getVoices work every other time?

I call:

window.speechSynthesis.getVoices(); // пустой массив

You need to get an array of vote objects.
As soon as I did it, it worked, after 5-10 page updates it stopped (both on document.readyand on window.onload).
What is the problem?
Task: check browser support and check for ru-RU voice

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lexstile, 2019-06-25
@lexstile

Decided so far:

window.speechSynthesis.addEventListener('voiceschanged', function() {
  if(isSpeechSynthesis() && isRuVoices()) {
    $('.voice').toggleClass('d-none');
  }
});

function isSpeechSynthesis() {
  return window.speechSynthesis || false;
}

function isRuVoices() {
  const arrVoices = window.speechSynthesis.getVoices();
  return arrVoices.find(function(item){
    return item.lang === 'ru-RU';
  });
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question