voice2txt v1.0.4
voice2txt
Simple voice recognition based on Google Speech API with handy promise callbacks.
Installation
npm i voice2txt --save
Dependencies
This module is based on node-record-lpcm16 & nodejs-speech
You need to install SoX and it must be available in your $PATH
.
For Mac OS
brew install sox
install with homebrew
For most linux disto's
sudo apt-get install sox libsox-fmt-all
For Windows
Configuration
At first you have to register in Google Cloud, follow steps:
Select or create a Cloud Platform project.
Enable billing for your project.
Enable the Google Cloud Speech API API.
Set up authentication with a service account so you can access the API from your local workstation.
Config object
speechClientConfig: object [speech.SpeechClient][you must define projectId & jsonKeyFilename - url to file]
timeSeconds: number [number of seconds to auto stop recording]
countTime: true | false [if true you'll see time count in cmd]
stopIfSilence: true | false [if true auto stop recording on (default) .5s of silence]
secondsOfSilence: number [time for stopIfSilence]
log: true | false [if true you'll see logs in cmd]
languageCode: string [recognition language]
recordProgram: string ['rec' (default) but also supports 'sox' and 'arecord', depends on OS]
There are two ways of configure solution
Local config
Voice2txt.config({
speechClientConfig: {
projectId: 'project-id-123',
jsonKeyFilename: './url-to-key-file.json'
},
stopIfSilence: true,
secondsOfSilence: 0.5,
languageCode: 'pl-PL'
}).startRecord().then((text) => {
console.log('Text: ' + text);
}).catch(() => {
console.log(`I didn't uanderstand what you've said`);
});
Global config
const Voice2txt = require('voice2txt');
Voice2txt.globalConfig({
speechClientConfig: {
projectId: '',
jsonKeyFilename: './url-to-key-file.json'
},
timeSeconds: 3,
countTime: true,
languageCode: 'pl-PL'
});
You can also overwrite global config for one of instance
Voice2txt.config({
timeSeconds: 5
}).startRecord().then((text) => {
console.log('Text: ' + text);
});
Usage
String literal available
const Voice2txt = require('voice2txt');
Voice2txt.globalConfig({
speechClientConfig: {
projectId: '',
jsonKeyFilename: './url-to-key-file.json'
},
countTime: true,
log: true
});
function error(err) {
console.log(`I didn't uanderstand what you've said`);
}
function success(text) {
console.log('Text: ' + text);
}
Voice2txt.config({
timeSeconds: 3,
languageCode: 'pl-PL'
}).then(success).catch(error).startRecord();
Methods
then(function)
success callback (string - recognized voice in text)
catch(function)
error callback (error object)
startRecord()
run voice recognition
stopRecord()
stop recognition and promise one of callbacks
config(object)
config
globalConfig(object)
global config
License
This project is licensed under the MIT License - see the LICENSE.md file for details