-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trigger #20
Merged
Trigger #20
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c47cc19
add trigger event so users can mantually start streaming detection
evancohen de09a7b
simple markdown file for documentation. website coming soon(ish) :smile:
evancohen 1791bfc
fix "unused" eslint error
evancohen ddcb5b6
0.1.2
evancohen 8dcd68b
make index and keyword optional paramaters to trigger
evancohen 8cb562d
using int for hotword trigger
evancohen a5d9560
0.1.3
evancohen 3535299
Merge branch 'master' into trigger
evancohen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,102 @@ | ||
## 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 into `Sonus.trigger` | ||
This will throw a `NOT_STARTED` exception if you have not started sonus when this is called. | ||
|
||
**Example:** | ||
``` javascript | ||
Sonus.trigger(sonus) | ||
``` | ||
sonus will be triggered with a hotword index of `0` and a hotword of `"triggered"` | ||
|
||
While it's not officially supported, If you want to trigger a specific index/hotword you can call `trigger` directly on the initialized sonus object | ||
**Example:** | ||
``` javascript | ||
sonus.trigger(0, 'hotword') | ||
``` | ||
|
||
## 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,36 @@ | ||
'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) | ||
} 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() | ||
} | ||
}) | ||
|
||
//Will use index 0 with a hotword of "triggered" and start streaming immedietly | ||
Sonus.trigger(sonus) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you actually want string 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should fallback to zero, but I think in order to best support all scenarios users should be able to pass in an index and a hotword to the trigger function (to accurately simulate the triggering of a specific hotword in case they have hotwords that perform different actions).
Proposed API
High flexibility and easy to use, or is this crazy 🍌s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You used a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah - it's actually supposed to be a string... My proposal was wrong.