https://github.com/hackergrrl/pi-voice-command-google
Recognize a single voice command on a Raspberry Pi using the Google Speech API.
https://github.com/hackergrrl/pi-voice-command-google
Last synced: 7 months ago
JSON representation
Recognize a single voice command on a Raspberry Pi using the Google Speech API.
- Host: GitHub
- URL: https://github.com/hackergrrl/pi-voice-command-google
- Owner: hackergrrl
- Created: 2019-06-07T03:59:35.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-22T19:17:37.000Z (almost 7 years ago)
- Last Synced: 2024-12-28T21:43:56.246Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pi-voice-command-google
> Recognize a single voice command on a Raspberry Pi using the Google Speech API.
## ~~ WARNING ~~
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](https://voice.mozilla.org/en) project!
## Setup
1. Install NodeJS 8.x.x or newer.
2. Follow Step 1 and Step 2 [on this Google Speech API quickstart page](https://cloud.google.com/speech-to-text/docs/quickstart-protocol). Save the JSON file it gives you somewhere handy.
3. Have ALSA set up for audio. If the `arecord` command is not available, you might need a package like `alsa-utils`.
4. Run `npm install pi-voice-command-google` to install the module.
## Usage
```js
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
```
## API
```js
var voice = require('pi-voice-command-google')
```
### var cancel = voice(keysPath[, ready], cb)
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](https://cloud.google.com/speech-to-text/docs/quickstart-protocol).
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.
## License
MIT