|
| 1 | +## API Methods |
| 2 | + |
| 3 | +Paramaters marked in **bold** are required |
| 4 | + |
| 5 | +### Require sonus and a cloud speech recognizer in your project: |
| 6 | +``` javascript |
| 7 | +const Sonus = require('sonus') |
| 8 | +const speech = require('@google-cloud/speech')({ |
| 9 | + projectId: 'streaming-speech-sample', |
| 10 | + keyFilename: './keyfile.json' |
| 11 | +}) |
| 12 | +``` |
| 13 | +For more information about Google Cloud Speech see: https://cloud.google.com/speech/ |
| 14 | +Note: don't forget to enable billing! |
| 15 | + |
| 16 | +### Custom hotwords |
| 17 | +You can train and download custom hotwords for sonus from https://snowboy.kitt.ai |
| 18 | +In order to initialize Sonus you need to pass in 1 or more hotwords. |
| 19 | +Each hotword supports the following proporties: |
| 20 | +**`file`** - The path to your hotword model (either pmdl or umdl) |
| 21 | +**`hotword`** - The string that represents your hotword (ex: "sonus") |
| 22 | +`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 |
| 23 | + |
| 24 | +**Example:** (to be passed into the sonus constructor) |
| 25 | +``` javascript |
| 26 | +const hotwords = [ |
| 27 | + {file: '/mymodel.pmdl', hotword: 'sonus'}, |
| 28 | + {file: 'snowboy.umdl', hotword: 'snowboy'}] |
| 29 | +``` |
| 30 | + |
| 31 | +### Languages |
| 32 | +Sonus lets you customize the lenguage for streaming speech recognition. For details on supported lenguages see the docs for your streaming speech recognizer |
| 33 | + |
| 34 | +**Example:** (to be passed into the sonus constructor) |
| 35 | +``` javascript |
| 36 | +const lenguage = "en-US" |
| 37 | +``` |
| 38 | + |
| 39 | +### Initialize Sonus |
| 40 | +Sonus's initialization accepts two paramaters: |
| 41 | +**`options`** - an options object that contains your hotwords, lenguage, etc |
| 42 | + - **`hotwords`** - an array of recognizable hotwords |
| 43 | + - `lenguage` - streaming lenguage recognition |
| 44 | + - `dictionary` - [TODO] only supported by some streaming recognizers |
| 45 | +**`speechRecognizer`** - the speech recognizer of your choice |
| 46 | + |
| 47 | +**Example:** |
| 48 | +``` javascript |
| 49 | +const sonus = Sonus.init({ hotwords, language }, speech) |
| 50 | +``` |
| 51 | + |
| 52 | +### Start recognition |
| 53 | +Pass your initialized sonus object into `Sonus.start` |
| 54 | +**Example:** |
| 55 | +``` javascript |
| 56 | +Sonus.start(sonus) |
| 57 | +``` |
| 58 | + |
| 59 | +### Pause recognition |
| 60 | +Pass your initialized sonus object into `Sonus.pause`. |
| 61 | +Pausing recognition while streaming will not cancel the request, instead it will cause it to simulate the "end" of speech and return final results. |
| 62 | +**Example:** |
| 63 | +``` javascript |
| 64 | +Sonus.pause(sonus) |
| 65 | +``` |
| 66 | + |
| 67 | +### Resume recognition |
| 68 | +Pass your initialized sonus object into `Sonus.resume` |
| 69 | +**Example:** |
| 70 | +``` javascript |
| 71 | +Sonus.resume(sonus) |
| 72 | +``` |
| 73 | + |
| 74 | +### Stop recognition |
| 75 | +If you want to stop recognition enterly you can use `Sonus.stop` |
| 76 | +**Example:** |
| 77 | +``` javascript |
| 78 | +Sonus.stop(sonus) |
| 79 | +``` |
| 80 | +Note that after recognition is stopped it can not be started again without creating an enterly new sonus instance. |
| 81 | + |
| 82 | +### Trigger keyword/hotword manually |
| 83 | +You can manuall trigger a hotword by passing your initialized sonus object and an index into `Sonus.trigger` |
| 84 | +The indexes of your hotwords are base 1 and are deturmined by the order in which the hotwords are passed into `Sonus.init` |
| 85 | + |
| 86 | +**Exceptions** |
| 87 | +- `NOT_STARTED` - will be thrown if you have not started sonus when this is called. |
| 88 | +- `INVALID_INDEX` - will be thrown if you pass an invalid index. |
| 89 | + |
| 90 | +**Example:** |
| 91 | +``` javascript |
| 92 | +Sonus.trigger(sonus, 1) |
| 93 | +``` |
| 94 | +sonus will be triggered with a hotword index of `1` |
| 95 | + |
| 96 | +You can also optionally specify an index of `0` and an arbitrary hotword that will be returned in the `hotword` event |
| 97 | +**Example:** |
| 98 | +``` javascript |
| 99 | +sonus.trigger(sonus, 0, 'some hotword') |
| 100 | +``` |
| 101 | +sonus will be triggered with a hotword index of `1` and a hotword of `some hotword` |
| 102 | + |
| 103 | +Passing a hotword with a valid index will override the hotword name and trigger that hotword |
| 104 | +**Example:** |
| 105 | +``` javascript |
| 106 | +sonus.trigger(sonus, 1, 'override') |
| 107 | +``` |
| 108 | +## Events |
| 109 | +hotword |
| 110 | +partial-result |
| 111 | +final-result |
| 112 | +error |
0 commit comments