2

I am using the Web Speech API for text to speech and need to be able to determine the default voice. To do this I call speechSynthesis.getVoices() and enumerate the voices to find the one where default is true.

I am in the US an use the US English locale on all of my devices. In Chrome on Windows and Mac the default voice returned is Google US English. However on the Chromebook the default voice returned is Chrome OS German. Is that really the correct default?

Is there some other locale setting on the Chromebook that I'm missing? I have tried changing the default voice for ChromeVox (which was also Chrome OS German before I changed it) but no luck.

Or is there some way to pass a language to getVoices()?

HTML

The HTML language of my page is set to US English.

<!DOCTYPE html>
<html lang="en-US">

I have tried lang="en", removing the DOCTYPE declaration, etc. with no change.

Javascript

    var _voices = [];

    speechSynthesis.onvoiceschanged = listVoices;

    function listVoices() {
        _voices = speechSynthesis.getVoices();
    }

    function getDefaultVoice() {
        var voice = '';
        _voices.some(function(v) {
            if (v.default) {
                voice = v.name;
                return true;
            }
        });
        return voice;
    }
Sarah Elan
  • 2,465
  • 1
  • 23
  • 45
  • 1
    FWIW - all of the Chromebooks I manage for a school district default to Chrome OS German when ChromeVox is first enabled. They are Acer C720s. – Dan Jan 30 '15 at 18:02
  • To be a bit more clear, they display German, but the voice is still English. – Dan Jan 30 '15 at 18:11
  • My UK Dell 11 Chromebook is the same; the default flag is set on the German voice! If you set lang on the message to 'en-GB' then it automatically uses the GB voice without having to specifically go through the voices. – Danny Tuppeny Mar 18 '16 at 21:23

1 Answers1

0

I figured this out. My default was set to German. This guide from Treehouse explains the process:

http://blog.teamtreehouse.com/getting-started-speech-synthesis-api

Explicitly you do something like this:

var utterance = new SpeechSynthesisUtterance('Hello Treehouse');
var voices = window.speechSynthesis.getVoices();

utterance.voice = voices.filter(function(voice) { return voice.lang == 'en-GB'; })[0];

window.speechSynthesis(utterance);

Then just change the language to be whichever you need (i.e. American english etc). You get the list from the voices variable listed above and can explore in your developer tools.

James Milner
  • 879
  • 2
  • 11
  • 16
  • 1
    If you set lang on the `SpeechSynthesisUtterance` this seems to automatically use the first GB voice, which is slightly simpler than filtering the voices :) – Danny Tuppeny Mar 18 '16 at 21:23