Implement your own voice commands

Voice commands implementation guide

Voice Commands

For us a voice command is two simple things, a name and an action. When the name is pronounced by the user, the action is executed.

The voice command name is defined as any string, e.g. 'play music', '2', 'john doe', '!', etc. The action is a Javascript function.

Lets define a simple hello world voice command that is executed when the user pronounces "say hi".

Simple hello world command

var myCommand = {
    name: 'say hi',
    action: function () {
        alert('hello world');
    }
}
                    

When defining a command, name and action are required properties, but there are others useful to help us to accomplish more complex things.

Property Required Type Description
name yes string Define what the user should pronounce in order to be executed
action yes function Define the function that will be executed when the user pronounce the command
isActive no function Defaults to function(){ return true; }. You can control when the command is available to be executed.
group no string Defaults to ''. Useful to display to the user commands grouped by categories
help no string Defaults to ''. Useful to display to the user a description of the command when asks for help
switchToContext no string Defaults to ''. Useful to switch to a different context after execute the command

The last property of the table switchToContext introduces us the idea of something called "context". We'll learn about it into the following section, but first lets see a more complex command definition.

Annoying hello world command

var myCommand = {
    name: 'say hi',
    action: function () {
        document
            .querySelectorAll('p, a, span, li, button, th, td, h1, h2, h3, h4, h5, h6')
            .forEach(function(el) {
                el.textContent = 'hello!';
            })
    },
    group: 'Greetings',
    help: 'It shows "hello!" everywhere'
}
                    

Next: Contexts

Sobre a Ferramenta

Javier Perez UNLP Unigranrio

A extensão Handsfree for Web foi desenvolvido por Javier Pérez, a fim de trazer uma alternativa de navegação web.

O aplicativo foi apresentado como uma implementação de um modelo de navegação na web sem o uso das mãos, descrito no trabalho final de Navegação Mãos-Livres conduzido por comandos de voz para o grau de Ciência da Computação na Universidade Nacional de La Plata.

Colaboradores

Alunos da Universidade Unigranrio enviaram a versão em português da ferramenta.
Agradecimento especial a:

  • Matheus Freitas
  • João Victor Plessim
  • Gabriel Francisco
  • Guilherme Cabral
  • Lucas Hermida