JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q49775F
  • 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

Then you need to install docker.

Run vosk-api local server: sudo docker run -p 2700:2700 alphacep/kaldi-ru:latest

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 } = require('electron')
const {speechSaverHandler, connect2Vosk } = require('electron-vosk-speech/src/utils')

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

// then add this handler to your 'will-download' event
connect2Vosk(win.webContents, () => {
    win.webContents.session.on('will-download', function voskSpeechSaver(...rest){
        speechSaverHandler(app.getAppPath(), ...rest) // for new version
    })
})

Enjoy!