Using voice commands in a web app

I love to converse with devices like the Amazon Alexa and Google Home. I can check the weather, call an Uber or order a pizza simply by speaking.

Despite their intuitiveness, you won't find voice commands in many web applications. There are good reasons for this — lack of browser compatibility, difficulty of parsing natural language, etc.

That said, I still think the browser Speech Recognition APIs are an underused resource. For example, it might be intuitive to perform actions on a data table — sorting, filtering, etc. — by telling the table how data should be visualized.

I took a crack at building a general-purpose JavaScript module for attaching functions to voice commands. Here's how to implement it:

var voiceCommand = new VoiceCommand();  
voiceCommand.add('Show my recent records', function() {  
  // Code for displaying recent records in the table

When the user speaks the phrase Show my recent records, the corresponding function will fire. Here's the full code for the module (MIT licensed):