Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/orthagonal/electron-voice
real-time voice-to-text in electron
https://github.com/orthagonal/electron-voice
Last synced: about 1 month ago
JSON representation
real-time voice-to-text in electron
- Host: GitHub
- URL: https://github.com/orthagonal/electron-voice
- Owner: orthagonal
- Created: 2024-08-28T23:15:29.000Z (3 months ago)
- Default Branch: all_words
- Last Pushed: 2024-08-29T19:24:39.000Z (3 months ago)
- Last Synced: 2024-08-29T21:41:37.651Z (3 months ago)
- Language: Rust
- Size: 20 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# electron-voice
## A fast, complete speech-to-text interface for Electron
- works with any [Vosk model](https://alphacephei.com/vosk/models)
- runs the audio device in a dedicated process separate from Electron browser, so it is very fast and not subject to any browser security limitations
- sends identified speech back to Electron using the Neon bridge
- can do generalized speech recognition
- can take in a custom grammar to limit the recognized wordsYou can install the project with npm. In the project directory, run:
```sh
$ npm install
```This fully installs the project, including installing any dependencies and running the build.
## Building vosk-electron
If you have already installed the project and only want to run the build, run:
```sh
$ npm run build
```This command uses the [cargo-cp-artifact](https://github.com/neon-bindings/cargo-cp-artifact) utility to run the Rust build and copy the built library into `./index.node`.
## electron_main.js Example
```js
// import the module just like any other node dependency
const voiceModule = require('index.node');// define a handler that gets called any time new words are identified
function onWordsFound(words) {
console.log(words);
}
// resets the recognizer to prevent it from getting bogged down
const MAX_WORDS = 25;// get list of devices
const devices = voiceModule.listDevices();
// select a device from the list:
voiceModule.setMicName(devices[2]);
// download models from https://alphacephei.com/vosk/models
voiceModule.setPathToModel('vosk-model-small-en-us-0.15');
// you can specify a grammar to limit the recognized words and
// improve accuracy, this step is optional
voiceModule.setGrammar('["hello", "world"]');
voiceModule.startListener(onWordsFound, MAX_WORDS);
// wait for the model to load, the big ones can take a few minutes:
let interval;
interval = setInterval(() => {
if (voiceModule.isModelLoaded()) {
console.log('speech model loaded!');
mainWindow.webContents.send('modelReady', true);
clearInterval(interval);
}
}, 1000);
```### index.node
The Node addon—i.e., a binary Node module—generated by building the project. This is the main module for this package, as dictated by the `"main"` key in `package.json`.
Under the hood, a [Node addon](https://nodejs.org/api/addons.html) is a [dynamically-linked shared object](https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries). The `"build"` script produces this file by copying it from within the `target/` directory, which is where the Rust build produces the shared object.
## Learn More
To learn more about Neon, see the [Neon documentation](https://neon-bindings.com).
To learn more about Rust, see the [Rust documentation](https://www.rust-lang.org).
To learn more about Node, see the [Node documentation](https://nodejs.org).
for different platforms:
rustup default stable-x86_64-pc-windows-msvc # For 64-bit
rustup default stable-i686-pc-windows-msvc # For 32-bitbinaries:
https://github.com/alphacep/vosk-api/releasesmodels:
https://alphacephei.com/vosk/models