Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
text to speech web api results in error on voice setting

on a button click I want to say blue sky in en-US language
this code results in error on utterThis.voice line
pls help

var synth = window.speechSynthesis;

$('button').on('click', function(){
    var utterThis = new SpeechSynthesisUtterance('blue sky');
        utterThis.rate = 1;
        utterThis.pitch = 1;
        utterThis.voice = {voiceURI: 'Google US English', name: 'Google US English', lang: 'en-US', localService: false, default: false};
    synth.speak(utterThis);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>CLICK</button>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to use one of the voices returned by .getVoices - assigning a plain object to .voice won't work.

$('button').on('click', function() {
  var utterThis = new SpeechSynthesisUtterance('blue sky');
  utterThis.rate = 1;
  utterThis.pitch = 1;

  for (const v of speechSynthesis.getVoices()) {
    if (v.voiceURI === 'Google US English') {
      utterThis.voice = v;
    }
  }
  speechSynthesis.speak(utterThis);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>CLICK</button>

The voices returned by .getVoices are verified by the browser / operating system to be supported, and are clearly tied to an underlying service that translates the text into speech - a plain object, on the other hand, does not, which is why a plain object doesn't work.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda