Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make my web browser speak programmatically?

Tags:

javascript

Is it possible to have a website speak a welcome message to users programmatically?

Suppose I wanted to greet users with an audio message upon successful login to my website. I know that I could record a greeting message(i.e. as an MP3), and play that, but I would want to be able to do this programmatically, since all users' names would be different.

For example, I might want to say Welcome, John Doe when John Doe logs in.

How could I do this with plain javascript?

NOTE: This is not intended for use in a production system, but rather intended to be used as a smaller portion of a bigger UX experiment.

like image 858
grizzthedj Avatar asked Jan 29 '18 15:01

grizzthedj


People also ask

How do I make text speak in HTML?

On any web page, open up the developer tools console and enter the following code: speechSynthesis. speak(new SpeechSynthesisUtterance("Hello, this is your browser speaking.")); Your browser will speak the text "Hello, this is your browser speaking." in its default voice.

How do I add text-to-speech on my website?

Choose a Text-to-Speech voiceVisit the Google Cloud Text-to-Speech home page. Enter some sentences. Try different WaveNet voices. Play with the pitch and speed sliders until you find a voice you like.


1 Answers

For window.speechSynthesis.speak() to render audio output at Chromium browser the user needs to have speech-dispatcher installed and launch the browser with --enable-speech-dispatcher flag.

  • How to use Web Speech API at chromium?

onvoiceschanged event handler and window.speech.synthesis.getVoices() needs to be called to populate the list of available voices. The API is not straightforward; .getVoices() may need to be called twice for the SpeechSynthesisVoice objects to populate the array returned by .getVoices().

Note that there is a potential for the calls to .speak() to be placed in a queue and not be rendered as audio output, which is not immediately evident; calling window.speechSynthesis.cancel() clears the queue, where the audio output could then be rendered unexpectedly.

  • speechSynthesis.getVoices() is empty array in Chromium Fedora

You can then use window.speechSynthesis.speak().

Have been trying for some time now to get SSML parsing enabled by default at Chromium browser for *nix; without using an external web service which requires either some form of EUA or is not free as in beer.

The list of entities that have contacted and questions asked to achieve this is quite lengthy, for example

  • SSML parsing implementation at browsers

  • How to extract SSML parsing code of espeak to implement SSML parsing at SpeechSynthesisUtterance?

  • How to set SSML parsing to on at user configuration file?

  • Why hasn't Issue 88072 and Issue 795371 been answered? Are Internals>SpeechSynthesis and Blink>Speech dead?

Firefox at *nix also does not parse SSML.

Perhaps with more interest by users at large we can finally get this feature enabled by default.

Though there are workarounds for SSML parsing without using an external web service; this first link below is still unanswered; though includes PHP code that calls the binary using shell_exec() following $_POST to a local server

  • How to programmatically send a unix socket command to a system server autospawned by browser or convert JavaScript to C++ souce code for Chromium?

  • SpeechSynthesisSSMLParser

Note, that there are several bug with the current Web Speech API implementation, notably that changing volume property at SpeechSynthesisUtterance has no effect on audio output at both Chromium and Firefox

  • Setting SpeechSynthesisUtterance.volume does not change volume of audio output of speechSynthesis.speak()

  • Setting SpeechSynthesisUtterance.volume does not change volume of audio output of speechSynthesis.speak()

There is also a bug when using .pause() and .resume(), which encountered when trying to programmatically parse <break> element of SSML

  • "speak speak slash" is audio output of .speak() following two calls to .speak(), .pause() and .resume()

An alternative to using the apparently dead Web Speech API is speak.js which was created by porting espeak to JavaScript or meSpeak.js, which is a fork of speak.js. espeak-ng is now actively maintained, for example using a modified version of meSpeak.js

  • generate audio file with W3C Web Speech API

or using online dictionaries which serve voice files reflecting the word

  • How to create or convert text to audio at chromium browser?

Interestingly, after posting that Answer the "gstatic" "dictionary" no longer served the audio files.

Fortunately, we have

  • mozilla/voice-web

This is a web, Android and iOS app for collecting speech donations for the Common Voice project.

which is quite active.


We can also use Native Message at both Chromium/Chrome and Firefox to call interact with the native shell and call the binary itself

  • How to parse JSON from stdin at Chrome Native Messaging host?

  • How to parse JSON from stdin at Native Messaging host?

  • Chrome Native Messaging throwing error when sending a base64 string to client

this code achieves expected result with minimal modification using Native Messaging

  • Chrome Native messaging with PHP

or as a drastic measure, change the binary

  • How to set options of commands called by browser?

(opinion, supported by facts follow)

There is a substantial web service market for speech synthesis technologies, both in the generation thereof ( "[L]yrebird") and the recognition of - for profit i.e.g., "*lexa"; "*olly"; (*bm) "*atson *luemix"; (*oogle) "*ctions"; etc.

It is up to open source developers to continue efforts directed towards maintaining open source (FOSS; FLOSS) speech synthesis technologies at open source browsers. If we want these technologies to be implemented in browsers by default, open source developers have to compose the code to make that happen.

like image 144
guest271314 Avatar answered Sep 20 '22 18:09

guest271314