Implement your own voice commands

Voice commands implementation guide

Modules

Importing modules is the main way to customize the Handsfree for Web extension.

A module is a Javascript file .js containing a javascript object or a function that returns an object.

Object Module

{
    //module properties
}
                    
Dynamic Module

function () {
    return {
        //module properties
    }
})
                    

The object module needs to define some properties, name and contexts, in order to be able to provide voice commands.

Lets see how the font picker commands fit into a voice commands module.

Font Picker Module

{
    name: 'Font Picker',
    description: 'Allows you to switch the font of every page',
    icon: 'fa-font',
    contexts: [{
        context: 'root', 
        commands: [{
            name: 'switch font',
            action: function () { },
            group: 'Font Picker',
            help: 'Switch website font',
            switchToContext: 'font-picker'
        }]
    }, {
        context: 'font-picker',
        commands: [{
            name: 'serif',
            action: function () {
                document.body.style.fontFamily = "serif"
            },
            group: 'Fonts',
            help: 'Switch website font to serif',
            switchToContext: 'root'
        }, {
            name: 'sans serif',
            action: function () {
                document.body.style.fontFamily = "sans-serif"
            },
            group: 'Fonts',
            help: 'Switch website font to sans-serif',
            switchToContext: 'root'
        }, {
            name: 'monospace',
            action: function () {
                document.body.style.fontFamily = "monospace"
            },
            group: 'Fonts',
            help: 'Switch website font to monospace',
            switchToContext: 'root'
        }]
    }]
}
                    

A module could be imported into the Handsfree for Web extension's page after click over the "+ Add Module" button placed in the left bottom corner.

Handsfree for web options page

There are a few more module properties useful to implement more complex behaviors

Property Required Type Description
name yes string Defines the module name
description no string Defaults to ''. Defines the module description the user will see into the extension page
icon no string Defaults to ''. Defines the module icon the user will see into the extension page. Check fontawesome.io for examples.
i18n no object Defaults to {}. Allows to define texts for different languages at module level
isActive no function Defaults to function() { return true; }. This function is called to know if the module could be loaded
contexts no array Defaults to []. Defines new contexts or extends existing ones with voice commands

Next: website voice commands

Acerca de esta herramienta

Javier Perez UNLP Unigranrio

La extensión Handsfree for Web fue desarrollada por Javier Pérez, con el objetivo de brindar una forma alternativa de acceso a la web.

La aplicación fue presentada como ejemplo de un modelo de interacción web a través del uso exclusivo de comandos de voz, definido en el trabajo final Navegación web dirigida por comandos de voz correspondiente a la carrera de grado Lic. en Sistemas de la Universidad Nacional de La Plata.

Contribuyentes

Estudiantes de la Universidad Unigranrio enviaron la versión en portugués de la extension.
Gracias especiales a:

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