Lightweight JS Library To Control Website with Voice Commands - annyang

Lightweight JS Library To Control Website with Voice Commands - annyang
File Size: 134 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

annyang is a lightweight and fancy javascript library which allows the visitor to control your website using voice commands that support multiple languages. annyang plays nicely with all browsers, progressively enhancing browsers that support SpeechRecognition, while leaving users with older browsers unaffected.

How to use it:

1. Include annyang.min.js javascript library on your web page

<script type="text/javascript" src="annyang.min.js"></script>

2. The javascript

<script type="text/javascript">
var commands = {
  // annyang will capture anything after a splat (*) and pass it to the function.
  // e.g. saying "Show me Batman and Robin" is the same as calling showFlickr('Batman and Robin');
  'show me *term': showFlickr,

  // A named variable is a one word variable, that can fit anywhere in your command.
  // e.g. saying "calculate October stats" will call calculateStats('October');
  'calculate :month stats': calculateStats,

  // By defining a part of the following command as optional, annyang will respond to both:
  // "say hello to my little friend" as well as "say hello friend"
  'say hello (to my little) friend': greeting
};

var showFlickr = function(term) {
  var url = 'http://api.flickr.com/services/rest/?tags='+tag;
  $.getJSON(url);
}

var calculateStats = function(month) {
  $('#stats').text('Statistics for '+month);
}

var greeting = function() {
  $('#greeting').text('Hello!');
}

</script>

This awesome jQuery plugin is developed by TalAter. For more Advanced Usages, please check the demo page or visit the official website.