Recognize a single voice command on a Raspberry Pi using the Google Speech API.
Recognize a single voice command on a Raspberry Pi using the Google Speech API.
Google demands personal information, including credit card billing information in order to use their service. Further, at time of writing, only 60 minutes of speech is free per month before you are charged. This is soooo far from a good solution, but it's the best I've been able to find for free voice recognition. To help the development of Free/Libre Open Source voice recognition, please contribute your voice to the Common Voice project!
arecord
command is not available, you might need a package like alsa-utils
.npm install pi-voice-command-google
to install the module.var voice = require('pi-voice-command-google')
var fs = require('fs')
var keysPath = './speech_keys.json'
voice(keysPath, function (err, res) {
if (err) throw err
console.log('Transcript:', res)
})
and saying 'hello world' aloud, outputs
hello world
var voice = require('pi-voice-command-google')
Returns a function cancel
that can be used to terminate microphone recording
and upload to Google servers.
keysPath
is a path to a JSON file: whatever Google gives you when you set up a Speech API project
here.
Otherwise, cb(err, res)
is called. res
will be a string with the contents
of what the Google machinery heard you say.
ready
is optional, and is a function that will be called once the mic is set
up and recording is starting.
Right now, this function is hardcoded to abort after 3 seconds of silence (no
command given; null
as res
), or after 1 second of silence after a command
is given.
MIT