Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Speech API Custom Words

I read through the W3C docs on this and I'm thinking that custom words come from custom grammar, but I tried going to this demo and in the console entered the following javascript:

recognition.grammars.addFromString('foo');

Which ran fine and recognition.grammars[0].src returns: "data:application/xml,foo"

Note: 'foo' is not the word I'm interested in, but the word I'm interested in isn't an english word, using 'foo' for the example. When I speak my custom word normally, it thinks I'm saying something else (which makes sense). I'm using 'foo' here to protect my brand :)

So what I want is to be able to say "Hey, foo" similar to how "Ok, Google" works. But my "foo" word is not an actual word so the SpeechRecognitionResult doesn't have my custom word.

Am I misunderstanding how to add custom words, or is this not possible today?

like image 513
kentcdodds Avatar asked Sep 16 '13 14:09

kentcdodds


People also ask

How do I add text to speech on my website?

To use Read Aloud, navigate to the web page you want to read, then click the Read Aloud icon on the Chrome menu. In addition, the shortcut keys ALT-P, ALT-O, ALT-Comma, and ALT-Period can be used to Play/Pause, Stop, Rewind, and Forward. You may also select the text you want to read before activating the extension.

How good is Web Speech API?

The Web Speech API is powerful and somewhat underused. However, there are a few annoying bugs and the SpeechRecognition interface is poorly supported. speechSynthesis works surprisingly well once you iron out all of its quirks and issues.

Is Google Text to Speech API free?

Text-to-Speech is priced based on the number of characters sent to the service to be synthesized into audio each month. You must enable billing to use Text-to-Speech, and will be automatically charged if your usage exceeds the number of free characters allowed per month.


1 Answers

When I speak my custom word normally, it thinks I'm saying something else (which makes sense).

Google provides very limited implementation of speech API without support for grammars, see the question about that:

Grammar in Google speech API

Morever, even the original specification is not complete in terms of grammars and their handling.

So what I want is to be able to say "Hey, foo" similar to how "Ok, Google" works. But my "foo" word is not an actual word so the SpeechRecognitionResult doesn't have my custom word.

This task is not a speech recognition task so it couldn't be solved effectively by a speech recognition engine, it requires keyword spotting because it need to filter all the speech except your keyword.

You could try to implement this using Pocketsphinx javascript library (http://cmusphinx.sourceforge.net/2013/06/voice-enable-your-website-with-cmusphinx/). With pocketsphinx, it's easier to debug pronunciation issues there too.

See also Web Speech API - SpeechGrammar which specifically describes support for grammars.

like image 175
Nikolay Shmyrev Avatar answered Sep 28 '22 08:09

Nikolay Shmyrev