Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/msub2/sepia-speechrecognition-polyfill
A polyfill for SpeechRecognition built to function with a SEPIA STT server.
https://github.com/msub2/sepia-speechrecognition-polyfill
polyfill sepia speech-recognition speech-to-text stt webspeech webspeech-api
Last synced: 28 days ago
JSON representation
A polyfill for SpeechRecognition built to function with a SEPIA STT server.
- Host: GitHub
- URL: https://github.com/msub2/sepia-speechrecognition-polyfill
- Owner: msub2
- License: mit
- Created: 2022-12-04T20:59:52.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-15T21:31:31.000Z (over 1 year ago)
- Last Synced: 2024-12-01T21:37:15.521Z (about 1 month ago)
- Topics: polyfill, sepia, speech-recognition, speech-to-text, stt, webspeech, webspeech-api
- Language: JavaScript
- Homepage:
- Size: 158 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SEPIA SpeechRecognition Polyfill
An implementation of the SpeechRecognition portion of the [Web Speech API](https://wicg.github.io/speech-api/) built to function with a [SEPIA STT server](https://github.com/SEPIA-Framework/sepia-stt-server). This polyfill allows for developers to have consistent cross-platform
support for speech recognition, including on platforms that do not have access to the Web Speech API natively.This polyfill attempts to conform to the existing specification draft as close as possible. Any deviations will be noted below.
## Setup
### Installation
For use with Node or NPM:
```bash
npm i sepia-speechrecognition-polyfill
```You can also load it from a CDN link:
```text
https://cdn.jsdelivr.net/npm/[email protected]
https://unpkg.com/[email protected]
```### Building Locally
```bash
git clone https://github.com/msub2/sepia-speechrecognition-polyfill
cd sepia-speechrecognition-polyfill
npm i
npm run build
```## Usage
This polyfill requires you to connect to a SEPIA STT server. For more detailed instructions on how to set up a SEPIA STT server, you can refer to the setup instructions on the main repo [here](https://github.com/SEPIA-Framework/sepia-stt-server#quick-start-with-docker).
### API
The polyfill exports a function, `sepiaSpeechRecognitionInit()`, and a class, `SepiaSpeechRecognitionConfig`.
`sepiaSpeechRecognitionInit` takes in a `SepiaSpeechRecognitionConfig` as a parameter and returns the polyfilled SpeechRecognition class.
`SepiaSpeechRecognitionConfig` contains properties for configuring your connection to the SEPIA STT server, which are as follows:
|Property|Description|Default Value|
|-|-|-|
|`serverUrl`|The URL for the SEPIA STT server.|`"http://localhost:20741"`|
|`clientId`|The client ID to authenticate as with the SEPIA STT server.|`"any"`|
|`accessToken`|The access token used to authenticate with the SEPIA STT server. **On a default server installation, which is set to use a common access token, this is set to `test1234`.** If the server is set to use individual tokens instead, this should be set to the corresponding token for the clientId.|`"test1234"`|
|`task`|Allows for selecting a task-specific model without knowing its exact name.|`""`|
|`model`|The name of the ASR model to use on the server. This does not need to be set if language is already set.|`""`|
|`optimizeFinalResult`|If set to true, will optimize final results by converting numbers and ordinals expressed as words into integers (i.e. one -> 1, third -> 3rd, etc).|`true`|
|`engineOptions`|Allows you to set options for features that may only be available in certain engines used by the server. An example would be Vosk's speaker detection, which is not available in Coqui.|`{}`|### Example
The following is an example of how to utilize the polyfill to support speech recognition across any browser:
```js
import { sepiaSpeechRecognitionInit, SepiaSpeechRecognitionConfig } from './sepia-speechrecognition-polyfill.min.js';const config = new SepiaSpeechRecognitionConfig();
// Set configuration options specific to your SEPIA STT serverconst SpeechRecognition = window.webkitSpeechRecognition || sepiaSpeechRecognitionInit(config);
const speechTest = new SpeechRecognition();
speechTest.onerror = (e) => console.log(e.error, e.message);
speechTest.onresult = (e) => console.log(`${e.results[0][0].transcript} ${e.results[0].isFinal}`);
speechTest.interimResults = true;
speechTest.continuous = true;const micButton = document.getElementById("micButton");
let toggled = false;
micButton.addEventListener('pointerup', () => {
if (!toggled) speechTest.start()
else speechTest.stop();
toggled = !toggled;
});
```## Unimplemented Features
- The error codes `aborted`, `audio-capture`, and `bad-grammar` are not currently used by the polyfill.
- Grammars are not currently implemented. See [this issue](https://github.com/msub2/sepia-speechrecognition-polyfill/issues/1) for a more in-depth discussion about implementing grammars.## Behavior Differences
- From my testing, this polyfill actually behaves closer to spec than Chromium's implementation in regards to how `continuous` works.
- On Chrome, once the first final transcript is received, recognition seems to stop, and it only returns that last transcript no matter how much you say after that. The polyfill continuously returns finalized transcripts after a set period of no speech from the user.
- The polyfill will attempt to infer the `lang` property based on the document language or `navigator.language`. Chromium does not.
- Chromium censors curse words/swears. The polyfill does not :)## Acknowledgements
Very special thanks goes out to [Florian Quirin](https://github.com/fquirin), maintainer of [SEPIA](https://github.com/SEPIA-Framework), for creating so much of the code that this polyfill relies on.