Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!