JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q61288F
  • License ISC

Lightweight Speech Recognition Library for Electron. Based on [nodejs-speech-kiosk-usercase](https://www.npmjs.com/package/nodejs-speech-kiosk-usercase) and [vosk-api](https://github.com/alphacep/vosk-api).

Package Exports

  • electron-vosk-speech

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (electron-vosk-speech) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Electron-vosk-speech

Lightweight Speech Recognition Library for Electron. Based on nodejs-speech-kiosk-usercase and vosk-api.

Requirements: Python 3.8

  1. Install:

yarn add electron-vosk-speech

To install python, read this guide.

sudo apt-get update
sudo apt-get install python3.8
pip3 install vosk
  1. Then, you need to download vosk's speech model: For example:
#download and save 2 models (ru, en)
cd node_modules/electron-vosk-speech/scripts
sh dl_models.sh

You can find list of vosk pretrained models here.

Then, you can find all available lang-models in file src/models.js

Example usage:

Add this to Electron's render process:

const {Recognizer} = require('electron-vosk-speech')
const {ipcRenderer} = require('electron')

const Rec = new Recognizer({
    ipcRenderer, 
    onSpeechRecognized: res => console.log('РЕЗУЛЬТАТ! ' + JSON.stringify(res)), 
    onSpeechStart: () => console.log('ГОВОРИТ!'), // fires on speech started
    onSpeechEnd: () => console.log('ЗАМОЛЧАЛ!'), // fires on speech ended
    options: {
        isSpeech2Text = true,
        autoInit = true,
        forced = true, // forced start recording
        idleDelay = 5000,
        languageCode = 'ru',
        harkOptions = {},
        gsFormat = false // if true, returns result in GoogleSpeech format
        // for backward compatibility with solutions based on GoogleSpeech
    }
})

// Rec.startAll() - start listening, recording and recognize
// Rec.stopAll() - stop listening, recording and recognize

// Rec.startListening() - start listening
// Rec.stopListening() - stop listening

// Rec.stopRecognize() - stop recording and recognize
// Rec.startRecognize() - start recording and recognize

Add this to Electron's main process:

const { app, BrowserWindow, ipcMain } = require('electron')
const {speechSaverHandler} = require('electron-vosk-speech/src/utils')

const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
})

// than add this handler to your 'will-download' event
const projectPath = app.getAppPath()
win.webContents.session.on('will-download', function(...rest){
    speechSaverHandler(projectPath, ...rest)
})

Enjoy!