AGI voice recognizer for Asterisk [use Yandex or Google ASR]
Call to special extension, say "Vasya" and Asterisk connect you with Vasya! Excellent!
Voicer work as AGI-server. Voicer accept request from asterisk via AGI app. It run handler for each request. Handler command asterisk record file. After this send file to recognition service, receive text, search by text in source of data for finding concordance, if source have this text it return channel for call, voicer set dialplan vars RECOGNITION_STATUS as SUCCESS и RECOGNITION_CHANNEL for finded channel.
Use voicer-app http://github.com/antirek/voicer-app
in your work dir
$ npm install voicer [--save]
Add to your app.js code
var config = require('./config');
var Voicer = require('voicer');
var voicer = new Voicer(config);
voicer.start();
$ node app.js
{
server: {
port: 3000
},
processing: {
totalAttempts: 2,
playGreeting: true,
playBeepBeforeRecording: false
},
asterisk: {
sounds: {
onErrorBeforeFinish: 'invalid',
onErrorBeforeRepeat: 'invalid',
greeting: 'tt-monkeysintro'
},
recognitionDialplanVars: {
result: 'RECOGNITION_RESULT',
channel: 'RECOGNITION_CHANNEL'
}
},
record: {
directory: '/tmp',
type: 'wav',
duration: 2,
},
recognize: {
directory: '/tmp',
type: 'google', // ['yandex', 'google']
options: {
developer_key: 'dev_key'
}
},
lookup: {
type: 'file', // ['file', 'mongodb', 'mysql']
options: {
dataFile: 'data/peernames.json'
}
},
logger: {
console: {
colorize: true
},
syslog: {
host: 'localhost'
},
file: {
filename: '/var/log/voicer.log',
json: false
}
}
}
Write dialplan for call to AGI-server voicer like
[default]
exten=1000,1,AGI(agi://localhost:3000)
exten=1000,n,GotoIf($[${RECOGNITION_RESULT}=SUCCESS]?:default,1000,4)
exten=1000,n,Dial(${RECOGNITION_CHANNEL})
Also you can tune additional options in config.js.
Try find optimal value for duration of record.
Bugs?! Oh, contact with me. I want to eat them.
Yandex API key: https://developer.tech.yandex.ru/
Google API key: https://console.developers.google.com/
Voice speed dial on Asterisk http://habrahabr.ru/post/248263/ (russian)
- create collection in mongodb
For example:
mongoimport --db yourdb --collection yourcollection --type json --file peernames.json --jsonArray
// peernames.json sample in ./example/data
- set config.js work with mongodb
lookup: {
type: 'mongodb',
options: {
url: 'mongodb://localhost/yourdb',
collection: 'yourcollection'
}
}
- create db and table
CREATE DATABASE `voicer` CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE TABLE `peernames` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`channel` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
and fill table data
- set config.js work with mysql
lookup: {
type: 'mysql',
options: {
host: 'locahost',
port: 3306,
username: 'root',
password: '1234',
database: 'voicer',
table: 'peernames'
}
}
npm test
grunt