Voice Control for Websites With annyang!

Speech Recognition

It’s increasingly common to control your devices using speech.

Google has speech recognition built into the Chrome browser. Apple and other Android manufacturers have voice control built into their cell phones.

Now, thanks to annyang!, you can add voice control to your website. annyang! is a tiny javascript library that’s really easy to add to your site.

In this tutorial, you will learn how to use this library doing a quick example.

Step #1. Load annyang!

Inside any HTML file, add the following code just before the closing head tag:<script src=”https://cdnjs.cloudflare.com/ajax/libs/annyang/1.1.0/annyang.min.js”></script>

Step #2. Adding your voice command

Now that you’ve loaded annyang! you can now add your voice commands.

For this example we’re going use the voice command ‘Hello’ to get a response from the website. Add this code immediately after the code you added in Step 1:

<script>
window.onload = function(){
if (annyang) {
var commands = {
'Hello': function() {
alert('Hi! I can hear you.');
}
};
annyang.addCommands(commands);
annyang.start();
}
}
</script>

Step #3. Test the voice control

Open your HTML file using Google’s Chrome browser.

If everything is fine, you will see a notification on top of the browser. Click on the “Allow” button to give your file access to the computer’s microphone.

SpeechRecognition

Now say “Hello” and wait for the reply message:

SpeechRecognition

Author

  • Valentin Garcia

    Valentin discovered Joomla in 2010, and since then he has considered it as the best CMS. Valentin has been coding extensions and templates for Joomla for many years and truly enjoys helping people build their own websites with Open Source tools. He lives in San Julián, Jalisco, México.

    View all posts
0 0 votes
Article Rating
Subscribe
Notify of
guest

5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Lalitha
Lalitha
10 years ago

Hi Valentin Garcia, that works great as described. Can you kindly suggest me to use this for recognizing a part of spoken sentence. For ex: I should be able to recognize “Hello” from the spoken sentence “Hello Valentin Garcia”.
Thanks in advance.

Good day

htmgarcia
10 years ago
Reply to  Lalitha

Hi Lalitha,

didn’t tested your specific example, as long as you mention the word “Hello” inside a long sentence my thinking is Annyang should be able to recognize it.
Let me know how this result.
Kind regards,

Valentín

Sameeer
Sameeer
9 years ago
Reply to  Lalitha

Hi tried this demo but it did’t worked what would be wrong will you please tell me

Yaroslav Beloborodov
Yaroslav Beloborodov
9 years ago
Reply to  Sameeer

You required to add 2 more JS libraries for correct work.

JQuery and Angular.

Dhanush Kumar
Dhanush Kumar
7 years ago

what are the two more files. can send me the link.

5
0
Would love your thoughts, please comment.x
()
x