SpeechSynthesis.getVoices () - empty array in Chromium Fedora

Does the API support Chromium speech synthesis? Do I need to install voices? If so, how can I do this? I am using Fedora. Do I need voices like video to install an additional package to make it work?

I tried this code:

var msg = new SpeechSynthesisUtterance('I see dead people!'); msg.voice = speechSynthesis.getVoices().filter(function(voice) { return voice.name == 'Whisper'; })[0]; speechSynthesis.speak(msg); 

from the article Web Applications That Speak - Introduction to Speech Synthesis API

but the speechSynthesis.getVoices () function returns an empty array.

I also tried:

 window.speechSynthesis.onvoiceschanged = function() { console.log(window.speechSynthesis.getVoices()) }; 

the function is executed, but the array is also empty.

There is information on https://fedoraproject.org/wiki/Chromium for using the --enable-speech-dispatcher flag, but when I use it, I get a warning that the flag is not supported.

+4
source share
1 answer

Is the Speech Synthesis API supported by Chromium?

Yes, the Web Speech API has basic support in the Chromium browser, although there are several problems with the implementation of the Chromium and Firefox specifications, see Blink> Speech , Internal> SpeechSynthesis , Web Speech .

Do I need to install voices? If so, how can I do this? I am using Fedora. Is the voice similar to the video, do I need to install an additional package for this to work?

Yes, you need to install the voices. Chromium does not come with voices to set the SpeechSynthesisUtterance voice attribute by default, see How to use the Web Speech API on chrome? ; How to capture the generated sound from a window.speechSynthesis.speak () call? .

You can set the speech-dispatcher as the server for the system speech synthesis server and espeak as the speech synthesizer.

 $ yum install speech-dispatcher espeak 

You can also install the configuration file for speech-dispatcher in the user's home folder to set certain parameters for both speech-dispatcher and the output module that you use, for example espeak

 $ spd-conf -u 

Running Chromium with the --enable-speech-dispatcher flag automatically creates a connection to the speech-dispatcher , where you can set LogLevel between 0 and 5 to view the SSIP connection between the Chromium code and speech-dispatcher .

.getVoices() returns results asynchronously and requires a double call

see this electron problem on GitHub Speech Synthesis: No Voices # 586 .

 window.speechSynthesis.onvoiceschanged = e => { const voices = window.speechSynthesis.getVoices(); // do speech synthesis stuff console.log(voices); } window.speechSynthesis.getVoices(); 

or consists of an asynchronous function that returns a Promise with a value that is an array of votes

 (async() => { const getVoices = (voiceName = "") => { return new Promise(resolve => { window.speechSynthesis.onvoiceschanged = e => { // optionally filter returned voice by `voiceName` // resolve( // window.speechSynthesis.getVoices() // .filter(({name}) => /^en.+whisper/.test(name)) // ); resolve(window.speechSynthesis.getVoices()); } window.speechSynthesis.getVoices(); }) } const voices = await getVoices(); console.log(voices); })(); 
+3
source

Source: https://habr.com/ru/post/1275053/


All Articles