https://github.com/untemps/vocal
Class wrapped around the SpeechRecognition Web API
https://github.com/untemps/vocal
Last synced: 3 months ago
JSON representation
Class wrapped around the SpeechRecognition Web API
- Host: GitHub
- URL: https://github.com/untemps/vocal
- Owner: untemps
- License: mit
- Created: 2021-05-20T08:54:39.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-22T06:27:54.000Z (almost 4 years ago)
- Last Synced: 2024-05-30T16:37:44.174Z (about 1 year ago)
- Language: JavaScript
- Size: 316 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# @untemps/vocal
Class wrapped around the SpeechRecognition Web API


## Installation
```bash
yarn add @untemps/vocal
```## Basic Usage
Import `Vocal` to a file.
```javascript
import { Vocal } from '@untemps/vocal'// Check whether SpeechRecognition, Permissions and MediaDevices interfaces are supported
if (!Vocal.isSupported()) {
throw "Vocal is not supported"
return;
}// Create a Vocal instance (see below for all available option properties)
const options = {
lang: 'fr-FR',
}
const vocal = new Vocal(options)// Subscribe to Vocal instance events (see below for all available events)
vocal.addEventListener('speechstart', (event) => console.log('Vocal starts recording'))
vocal.addEventListener('speechend', (event) => console.log('Vocal stops recording'))
vocal.addEventListener('result', (event, result) => console.log('Vocal catches a result'))
vocal.addEventListener('error', (error) => throw error)// Start recording
vocal.start()// Stop/Pause recording
vocal.stop()// Abort recording entirely
vocal.abort()// Remove all attached listeners and delete the Vocal instance
vocal.cleanup()
```## Options
Options described below are those from the `SpeechRecognition` Web API.
Please this [this section](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition#properties) for more information.| Option | Type | Default | Description |
| ---------------- | ----------------- | ---------- | ----------------------------------------------------------------------------------------------------------------- |
| grammars | SpeechGrammarList | null | Grammars understood by the recognition [JSpeech Grammar Format](https://www.w3.org/TR/jsgf/) |
| lang | string | 'en-US' | Language understood by the recognition [BCP 47 language tag](https://tools.ietf.org/html/bcp47) |
| continuous | boolean | false | Whether continuous results are returned for each recognition, or only a single result |
| interimResults | boolean | false | Whether interim results should be returned or not. Interim results are results that are not yet final |
| maxAlternatives | number | 1 | Maximum number of SpeechRecognitionAlternatives provided per result |
| serviceURI | string | null | Location of the speech recognition service used by the current SpeechRecognition to handle the actual recognition |## Events
Events described below are those from the `SpeechRecognition` Web API.
Please this [this section](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition#events) for more information.| Event | Description |
| ----------- | ----------------------------------------------------------------------------------------- |
| audioend | Fired when the user agent has finished capturing audio for recognition |
| audiostart | Fired when the user agent has started to capture audio for recognition |
| end | Fired when the recognition service has disconnected |
| error | Fired when a recognition error occurs |
| nomatch | Fired when the recognition service returns a final result with no significant recognition |
| result | Fired when the recognition service returns a result |
| soundend | Fired when any sound — recognisable or not — has stopped being detected |
| soundstart | Fired when any sound — recognisable or not — has been detected |
| speechend | Fired when speech recognized by the recognition service has stopped being detected |
| speechstart | Fired when sound recognized by the recognition service as speech has been detected |
| start | fired when the recognition service has begun listening to incoming audio |