Yet another topic on Chromium + Speech Synthesis TTS (Raspberry)

1,214 views
Skip to first unread message

Juliosor

unread,
Jul 30, 2018, 9:38:37 AM7/30/18
to Chromium-discuss
After a lot of googling, visiting many forums (here, SO, askubuntu.comraspberrypi ...) and testing in many ways, I haven't found a solution (nor anyone else apparently), posts are either old, incomplete or unsolved. I come searching for solutions (and hell I will document them if found).

Desired Output

Chromium parses strings to audio with the native Javascript SpeechSyntesis library.

Problem

Chromium returns empty voices array first, then upon reload Ctrl + R finds all the voices, but returns a robotic-like, incomprehensible voice.

Code

<html>

<head>

<meta charset="utf-8"/>

<script>

window.speechSynthesis.onvoiceschanged = e => 
{
// Words to talk
var utterance = new SpeechSynthesisUtterance('Hello hell');
// This is empty
console.log(window.speechSynthesis.getVoices());

voices = window.speechSynthesis.getVoices();

// This is empty as well
console.log(voices);
utterance.voice = voices.filter(function(voice) { return voice.name == "english espeak-ng"; })[0];

// This is null
console.log(utterance.voice);
window.speechSynthesis.speak(utterance);

}

</script>

</head>

<body>

</body>

</html>

Output (in Chromium's Dev. console)

Array(0) x2
null

** Robotic noises **

After browser reload:

(95) [SpeechSynthesisVoice, SpeechSynthesisVoice, ...] x2
{SpeechSynthesisVoice {voiceURI: "english espeak-ng", name: "english espeak-ng", lang: "", localService: true, default: false}

** Robotic noises **

Deploy

From terminal: chromium-browser textToSpeech.html --enable-speech-dispatcher

System and software versions
  • Raspberry pi 3B+ 1GB 1.3
  • Raspbian GNU/Linux 9 (stretch)
  • Chromium 65.0.3325.181 Built on Raspbian 9.4
  • Advanced Linux Sound Architecture Driver Version k4.14.50-v7+
  • PulseAudio card 10.0
  • Installed --> speech-dispatcher 0.8.6
  • Installed --> eSpeak text-to-speech: 1.48.15  (eSpeak-ng not regular)
Notes
  • Installing regular eSpeak does nothing.
  • Using --enable-speech-synthesis flag is necessary for chromium to detect the voices, but raises a "You are using and unsupported command-line flag..." in the browser. Without this flag, no noise is ever made or voices ever detected in any reload.
  • A similar version of this code works fine in Chrome 67.0.3396.99 (32 bits) for Windows 10 (32 bits) (replacing voice.name for voice.lang == "en-UK" ).
  • No Google API keys are being used in either of the OS.
  • spd-conf and spd-conf -d do not exist or work in the Raspberry terminal.
  • External libraries like ResponsiveVoice.js work fine (so audio is OK).

guest271314

unread,
Dec 24, 2019, 1:27:05 AM12/24/19
to Chromium-discuss, juliosor...@gmail.com
There is no native Javascript SpeechSyntesis library per Web Speech API. 

Would suggest executing `speechSynthesis.cancel()` before each use of `speechSynthesis` at Chromium to clear the synthesis queue, defining a single instance of `speechSynthesis`, `const synth = speechSynthesis`, execute `let voices = synth.getVoices()` outside of `onvoiceschanged` event. `espeak-ng` voices begin with uppercase letter and `lang` is not set at Chromium.

`spd-conf` is in `python3-speechd` package.

```
    (async() => {
      const synth = speechSynthesis;
      const text = [...Array(10).keys()].join(" ");
      const handleVoicesChanged = async e => {
        const voice = synth.getVoices().find(({
          name
        }) => name.includes("English"));
        const utterance = new SpeechSynthesisUtterance(text);
        utterance.voice = voice;
        utterance.pitch = 0.33;
        utterance.rate = 0.1;
        const recorder = new MediaRecorder(stream);
        recorder.start();
        synth.speak(utterance);
      }
      synth.onvoiceschanged = handleVoicesChanged;
      let voices = synth.getVoices();
      console.log(voices);
      if (voices.length) {
        handleVoicesChanged();
      };

    })().catch(console.error);
```


Reply all
Reply to author
Forward
0 new messages