0.2.1 • Published 4 years ago

electron-vosk-speech v0.2.1

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

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!

0.2.1

4 years ago

0.2.0

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago