JSPM

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

  1. Install:

yarn add electron-vosk-speech

Then you need to install docker.

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

To restart: docker restart alphacep/kaldi-ru:latest To stop and clear vosk container: docker stop vosk

To clear all docker containers:

docker stop $(docker ps -aq)
docker rm $(docker ps -aq)

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
    }
})

// default values
<!-- const props = {
    sudo: false, // with sudo you can get an error now, so you need to configure docker to use without sudo, or other...
    autostart: true, // to autostart docker server
    docker: {
        name: 'vosk',
        container: 'alphacep/kaldi-ru',
        version: 'latest',
        port: '2700'
    }
} -->

const {VoskConnector} = require('electron-vosk-speech/src/utils')
const vosk = new VoskConnector({
    // sudo: true,
    autostart: 1,
    sudo: 0,
    docker: {
        image: 'neurocity/vosk-small-ru', //todo добавить ошибку, или убивание процесса, если данные имена не совпадают
        version: '0.0.2'
    },
    config: {
        word_list: words
    }
})
vosk.init(mainWindow.webContents, (ws) => {
    mainWindow.webContents.session.on('will-download', function voskSpeechSaver(...rest){
        vosk.speechSaverHandler(app.getAppPath(), ws, ...rest) // for new version
    })
})

Enjoy!