2

im trying to use web speech api to transcript a word in Portuguese, i set the property to 'pt-BR' ( unfortunately Portuguese - european is not supported) but, always replies in english.

Can someone help?

Thanks

code:

        <script type="text/javascript"> 
            var synth = window.speechSynthesis;
            function falatarea(){
                var utteranceY = new SpeechSynthesisUtterance();
                    utteranceY.text = "teste";
                    utteranceY.lang = "pt-BR";
                    utteranceY.voice = "pt-BR";
                    window.speechSynthesis.speak(utteranceY);
                    }
        </script>
Bruno
  • 41
  • 2
  • 8

1 Answers1

2

Seems like Chrome broke recently. I had code working, now its not.

https://code.google.com/p/chromium/issues/detail?id=582455

As a work-around, you can set the .voice

voices = window.speechSynthesis.getVoices()

var utterance = new SpeechSynthesisUtterance("lo que practico");

utterance.voice = voices[3];
utterance.lang = voices[3].lang;

window.speechSynthesis.speak(utterance);

Perhaps the API changed as before when a female/male voice were both available it was not possible to pick one in particular. I still set lang for other browsers (or older chromes).

Frank Schwieterman
  • 24,142
  • 15
  • 92
  • 130
  • Thanks for the reply! I tryed this code but i'm getting this error: "Uncaught TypeError: Cannot read property 'lang' of undefined". I did this too: http://stackoverflow.com/questions/21513706/getting-the-list-of-voices-in-speechsynthesis-of-chrome-web-speech-api but not working also... – Bruno Jan 30 '16 at 16:25
  • well the code is assuming at least 4 voices are returned, where voices[3] is you will need your own logic to select the appropriate voice. – Frank Schwieterman Jan 31 '16 at 13:01
  • yep, i used voice[15] wich is pt-BR, I think the problem is to put the voices into the array. its not working... – Bruno Jan 31 '16 at 13:57
  • Now, on my enterprise PC, the speech cames on PT-PT (actually this is new) but on my PC the speech cames in EN-EN. Google must be doing something on his voice systems... – Bruno Feb 01 '16 at 15:46
  • 1
    Google Chrome on android vs PC has different voice lists, maybe there is a Mac/PC difference too. You have to write code to sniff through and find the one you want (I have a list of preferred lang values, and pick the first available). – Frank Schwieterman Feb 02 '16 at 10:32
  • There is also this issue: https://bugs.chromium.org/p/chromium/issues/detail?id=586947. If anyone thinks they have the same issue, please star it for visibility with the Chrome folks. – Frank Schwieterman May 08 '16 at 03:22