-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add trigger event so users can mantually start streaming detection * simple markdown file for documentation. website coming soon(ish) 😄 * fix "unused" eslint error * 0.1.2 * make index and keyword optional paramaters to trigger * using int for hotword trigger remove console.log * 0.1.3
- Loading branch information
Showing
4 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
## API Methods | ||
|
||
Paramaters marked in **bold** are required | ||
|
||
### Require sonus and a cloud speech recognizer in your project: | ||
``` javascript | ||
const Sonus = require('sonus') | ||
const speech = require('@google-cloud/speech')({ | ||
projectId: 'streaming-speech-sample', | ||
keyFilename: './keyfile.json' | ||
}) | ||
``` | ||
For more information about Google Cloud Speech see: https://cloud.google.com/speech/ | ||
Note: don't forget to enable billing! | ||
|
||
### Custom hotwords | ||
You can train and download custom hotwords for sonus from https://snowboy.kitt.ai | ||
In order to initialize Sonus you need to pass in 1 or more hotwords. | ||
Each hotword supports the following proporties: | ||
**`file`** - The path to your hotword model (either pmdl or umdl) | ||
**`hotword`** - The string that represents your hotword (ex: "sonus") | ||
`sensitivity` - (default `'0.5'`) If you are getting a lot of false positives or are having trouble detecting your hotword adjusting this value shoud help | ||
|
||
**Example:** (to be passed into the sonus constructor) | ||
``` javascript | ||
const hotwords = [ | ||
{file: '/mymodel.pmdl', hotword: 'sonus'}, | ||
{file: 'snowboy.umdl', hotword: 'snowboy'}] | ||
``` | ||
|
||
### Languages | ||
Sonus lets you customize the lenguage for streaming speech recognition. For details on supported lenguages see the docs for your streaming speech recognizer | ||
|
||
**Example:** (to be passed into the sonus constructor) | ||
``` javascript | ||
const lenguage = "en-US" | ||
``` | ||
|
||
### Initialize Sonus | ||
Sonus's initialization accepts two paramaters: | ||
**`options`** - an options object that contains your hotwords, lenguage, etc | ||
- **`hotwords`** - an array of recognizable hotwords | ||
- `lenguage` - streaming lenguage recognition | ||
- `dictionary` - [TODO] only supported by some streaming recognizers | ||
**`speechRecognizer`** - the speech recognizer of your choice | ||
|
||
**Example:** | ||
``` javascript | ||
const sonus = Sonus.init({ hotwords, language }, speech) | ||
``` | ||
|
||
### Start recognition | ||
Pass your initialized sonus object into `Sonus.start` | ||
**Example:** | ||
``` javascript | ||
Sonus.start(sonus) | ||
``` | ||
|
||
### Pause recognition | ||
Pass your initialized sonus object into `Sonus.pause`. | ||
Pausing recognition while streaming will not cancel the request, instead it will cause it to simulate the "end" of speech and return final results. | ||
**Example:** | ||
``` javascript | ||
Sonus.pause(sonus) | ||
``` | ||
|
||
### Resume recognition | ||
Pass your initialized sonus object into `Sonus.resume` | ||
**Example:** | ||
``` javascript | ||
Sonus.resume(sonus) | ||
``` | ||
|
||
### Stop recognition | ||
If you want to stop recognition enterly you can use `Sonus.stop` | ||
**Example:** | ||
``` javascript | ||
Sonus.stop(sonus) | ||
``` | ||
Note that after recognition is stopped it can not be started again without creating an enterly new sonus instance. | ||
|
||
### Trigger keyword/hotword manually | ||
You can manuall trigger a hotword by passing your initialized sonus object and an index into `Sonus.trigger` | ||
The indexes of your hotwords are base 1 and are deturmined by the order in which the hotwords are passed into `Sonus.init` | ||
|
||
**Exceptions** | ||
- `NOT_STARTED` - will be thrown if you have not started sonus when this is called. | ||
- `INVALID_INDEX` - will be thrown if you pass an invalid index. | ||
|
||
**Example:** | ||
``` javascript | ||
Sonus.trigger(sonus, 1) | ||
``` | ||
sonus will be triggered with a hotword index of `1` | ||
|
||
You can also optionally specify an index of `0` and an arbitrary hotword that will be returned in the `hotword` event | ||
**Example:** | ||
``` javascript | ||
sonus.trigger(sonus, 0, 'some hotword') | ||
``` | ||
sonus will be triggered with a hotword index of `1` and a hotword of `some hotword` | ||
|
||
Passing a hotword with a valid index will override the hotword name and trigger that hotword | ||
**Example:** | ||
``` javascript | ||
sonus.trigger(sonus, 1, 'override') | ||
``` | ||
## Events | ||
hotword | ||
partial-result | ||
final-result | ||
error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict' | ||
|
||
const ROOT_DIR = __dirname + '/../' | ||
const Sonus = require(ROOT_DIR + 'index.js') | ||
const speech = require('@google-cloud/speech')({ | ||
projectId: 'streaming-speech-sample', | ||
keyFilename: ROOT_DIR + 'keyfile.json' | ||
}) | ||
|
||
const hotwords = [{ file: ROOT_DIR + 'resources/sonus.pmdl', hotword: 'sonus' }] | ||
const language = "en-US" | ||
const sonus = Sonus.init({ hotwords, language }, speech) | ||
|
||
try{ | ||
Sonus.trigger(sonus, 1) | ||
} catch (e) { | ||
console.log('Triggering Sonus before starting it will throw the following exception:', e) | ||
} | ||
|
||
Sonus.start(sonus) | ||
|
||
sonus.on('hotword', (index, keyword) => console.log("!" + keyword)) | ||
|
||
sonus.on('partial-result', result => console.log("Partial", result)) | ||
|
||
sonus.on('error', (error) => console.log(error)) | ||
|
||
sonus.on('final-result', result => { | ||
console.log("Final", result) | ||
if (result.includes("stop")) { | ||
Sonus.stop() | ||
} | ||
}) | ||
|
||
try{ | ||
Sonus.trigger(sonus, 2) | ||
} catch (e) { | ||
console.log('Triggering Sonus with an invalid index will throw the following error:', e) | ||
} | ||
|
||
//Will use index 0 with a hotword of "triggered" and start streaming immedietly | ||
Sonus.trigger(sonus, 0, "some hotword") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters