Speech Recognition in the Browser
Last Thursday I had a pleasure to give talk about Speech Recognition in the Browser at the Code Fellows in Seattle.
Many people were surprised how easy it is to add speech recognition to your website with pure JavaScript. So I thought I will share a few code snippets here. It works in Chrome only so far.
Recognizing speech
This is how you can translate speech to text:
You can also get the confidence level of the result:
You can get interim results:
Or different alternatives of recognized speech:
You can set a language, e.g., to Polish:
All above will stop recognition when you stop speaking. In order to do not stop recognition you need to set continuous flag to true. Additionally, this will treat every fragment of you speech as interim result, so you need to update onresult callback too:
Speech Recognition object has other callbacks (than onresult) that you can take advantage of:
Emitting speech
You can also change the speaker voice:
There is also other options you can set:
Summary
Speech is coming to the browser, and you can not stop it. The question is when most of websites will add voice support. Check out voiceCmdr - a library that I blogged about earlier this year, which helps to add voice commands to your websites in very easy way. You can also check out website that can be navigated with voice commands - you can find available commands in my blog post. You can find entire logic for voice commands support in this file (lines: 38-103).