GithubHelp home page GithubHelp logo

antirek / voicer Goto Github PK

View Code? Open in Web Editor NEW
95.0 11.0 35.0 480 KB

AGI-server voice recognizer for #Asterisk

License: MIT License

JavaScript 100.00%
asterisk dialplan agi recognition javascript voice voice-recognition voice-commands voice-control voice-assistant yandex google asr

voicer's Introduction

voicer

AGI voice recognizer for Asterisk [use Yandex, Google or Wit.ai ASR online services]

Call to special extension, say "Vasya" and Asterisk connect you with Vasya! Excellent!

Build Status

Workflow

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_RESULT as SUCCESS and RECOGNITION_TARGET for finded result.

After this voicer return control to dialplan. Build rules of dialplan using RECOGNITION_RESULT and RECOGNITION_TARGET.

Use

Install

$ npm install voicer -g

Run

voicer -p 3000 -t google -k <developer_key> -d /etc/voicer/peernames.json -r /var/records

run with --help for instructions

voicer --help

Configuration

Config.js

{
    agi: {
        port: 3000
    },
    processing: {
        totalAttempts: 2,
        playGreeting: true,
        playBeepBeforeRecording: false   //use system beep
    },
    asterisk: {
        sounds: {
            onErrorBeforeFinish: 'invalid',
            onErrorBeforeRepeat: 'invalid',
            greeting: 'beep'
        },
        recognitionDialplanVars: {
            status: 'RECOGNITION_RESULT',
            target: 'RECOGNITION_TARGET'
        }
    },
    record: {
        directory: '/tmp',
        type: 'wav',
        duration: 2,
    },
    recognize: {
        directory: '/tmp',
        type: 'witai',    // ['yandex', 'google', 'witai']
        options: {
            developer_key: '6SQV3DEGQWIXW3R2EDFUMPQCVGOEIBCR'
        }
    },
    lookup: {
        type: 'file',
        options: {
            dataFile: 'data/peernames.json'
        }
    }
};

Asterisk

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

Format peernames

[
    ....
    {
        "name": "Vasya",
        "target": "SIP/Sf567890",
        "variants": ["vasya", "vasya petrov"]
    },
    ....
]

Online peernames.json constructor

Errors?!

Bugs?! Oh, contact with me. I want to eat them.

Links

Yandex API key: https://developer.tech.yandex.ru/

Google API key: https://console.developers.google.com/

Wit.ai API key: http://wit.ai

Voice speed dial on Asterisk

New manual

Use with FreePBX

Development

Test

npm test

voicer's People

Contributors

antirek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

voicer's Issues

stepRepeatOnError TypeError: Cannot read property 'toLowerCase' of undefined at Promise

Добрый день!
voicer в связке с wit.ai . .. для настройки использовал эту статью https://voxlink.ru/kb/asterisk-configuration/golosovoj-nabor-v-asterisk-2/
До карантина все работало ... проблема где-то во время карантина возникла.
Если правильно понимаю, voicer сравнивает, но не выдает ответ ...
2020-6-11 22:30:56 - [32minfo [39m: 0000001 stepLookup
read file /etc/voicer/data/peernames.json
parsed [ { name: '333',
target: 'SIP/333',
variants: [ 'админ', 'иван валерьевич' ] } ]
2020-6-11 22:30:56 - [32minfo [39m: 0000001 stepRepeatOnError TypeError: Cannot read property 'toLowerCase' of undefined
at Promise (/usr/lib/node_modules/voicer/apps/agi/source/fileSource.js:11:24)
at new Promise ()
at FileSource.find (/usr/lib/node_modules/voicer/apps/agi/source/fileSource.js:10:12)
at fileReader.readFile.then.then.then (/usr/lib/node_modules/voicer/apps/agi/source/fileSource.js:48:23)
at
Спасибо!

Problem with install on FreePBX Distro

Привет.

Есть проблемы с установкой voicer на FreePBX Distro.
Версия дистрибутива - SNG7-PBX-64bit-1904 Release Date: May 2019

[root@pbx13 ~]# uname -a
Linux pbx13.local 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@pbx13 ~]# cat /etc/redhat-release
Sangoma Linux release 7.5.1805 (Core)
[root@pbx13 ~]# node -v
v8.11.3
[root@pbx13 ~]# npm -v
5.6.0

[root@pbx13 ~]# npm install voicer -g
....skip.....
/usr/bin/voicer -> /usr/lib/node_modules/voicer/app.js

[root@pbx13 ~]# voicer
bash: /usr/bin/voicer: /usr/bin/nodejs: bad interpreter: No such file or directory

Ок, ладно

[root@pbx13 ~]# ln -s /usr/bin/node /usr/bin/nodejs

Ещё раз:

[root@pbx13 ~]# voicer
no configfile: ./config.js

Ну ладно

[root@pbx13 ~]# export VOICER_CONFIGFILE=/etc/voicer/config

И ещё раз:

[root@pbx13 ~]# voicer
/etc/voicer/config.js:4
    },
     ^

SyntaxError: Unexpected token ,
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/lib/node_modules/voicer/app.js:8:16)

Хорошо, добавляем в начало конфига (взят из readme.md) "module.exports ="

[root@pbx13 ~]# voicer
config.js validated successfully! undefined
2019-8-20 16:32:36 - info: server started undefined

О, вроде взлетело.

Заходим на http://pbx_ip:3100
Логинимся с vasya / password - пустило
Пытаюсь прописать
name - vasya
target - SIP/1001
не получается - при нажатии на кнопки Add / Save ничего не происходит.

Попробовал сделать
[root@pbx13 ~]# touch /etc/voicer/data/peernames.json
[root@pbx13 ~]# chmod 777 /etc/voicer/data/peernames.json
[root@pbx13 ~]# voicer
config.js validated successfully! undefined
2019-8-20 16:40:19 - info: server started undefined

Не помогло.

Поменял в config.js
dataFile: 'data/peernames.json'
на
dataFile: '/etc/voicer/data/peernames.json'
После этого редактирование заработало.

В общем если есть интерес к охвату аудитории использующей FreePBX Distro - эти мелочи неплохо бы или поправить или в документацию перенести.

wit.ai does not work. google - work

[root@freepbx config]# pm2 logs voicer [--lines 1000]
[TAILING] Tailing last 15 lines for [voicer] process (change the value with --lines option)
/root/.pm2/logs/voicer-out.log last 15 lines:

/root/.pm2/logs/voicer-error.log last 15 lines:
0|voicer | ntick: true,
0|voicer | _started: true,
0|voicer | href: 'https://api.wit.ai/speech',
0|voicer | req: [Object],
0|voicer | response: [Circular],
0|voicer | originalHost: 'api.wit.ai',
0|voicer | originalHostHeaderName: 'host',
0|voicer | responseContent: [Circular],
0|voicer | _destdata: true,
0|voicer | _ended: true,
0|voicer | _callbackCalled: true },
0|voicer | toJSON: [Function: responseToJSON],
0|voicer | caseless: Caseless { dict: [Object] },
0|voicer | read: [Function],
0|voicer | body: <Buffer 7b 0a 20 20 22 65 72 72 6f 72 22 20 3a 20 22 42 61 64 20 61 75 74 68 2c 20 63 68 65 63 6b 20 74 6f 6b 65 6e 2f 70 61 72 61 6d 73 22 2c 0a 20 20 22 63 ... > } }

Log for analys

Log all attempts to recognition and successful too. Show by day what was recognized.

stepRepeatOnError Error: Lookup: not found in source и stepError Error: Lookup: not found in source

Добрый вечер!

[root@freepbx voicer]# npm install voicer -g
npm WARN deprecated [email protected]: request has been deprecated, see request/request#3142
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Use uuid module instead
/root/.nvm/versions/node/v10.21.0/bin/voicer -> /root/.nvm/versions/node/v10.21.0/lib/node_modules/voicer/bin/agi.js

voicer в связке с wit.ai
Что-то опять изменилось...
Если правильно понимаю, voicer сравнивает, но не выдает ответ ...

agi server started on port 3000 with config { agi: { port: 3000 },
processing:
{ totalAttempts: 2,
playGreeting: true,
playBeepBeforeRecording: false },
asterisk:
{ sounds:
{ onErrorBeforeFinish: 'ostavaytes',
onErrorBeforeRepeat: 'eseraz',
greeting: 'beep' },
recognitionDialplanVars: { status: 'RECOGNITION_RESULT', target: 'RECOGNITION_TARGET' } },
record: { directory: '/tmp', type: 'wav', duration: 3 },
recognize:
{ directory: '/tmp',
type: 'witai',
options: { developer_key: 'тутверныйключ' } },
lookup:
{ type: 'file',
options: { dataFile: '/etc/voicer/data/peernames.json' } } }
2021-8-5 20:17:46 - �[32minfo�[39m: 0000001 -- start processing
2021-8-5 20:17:46 - �[32minfo�[39m: 0000001 variables {"agi_network":"yes","agi_request":"agi","agi_channel":"SIP/Alina_Sip_742843_1-000001ed","agi_language":"ru","agi_type":"SIP","agi_uniqueid":"1628183856.750","agi_version":"16.11.1","agi_callerid":"89162911537","agi_calleridname":" Иван Валерьевич","agi_callingpres":"0","agi_callingani2":"0","agi_callington":"0","agi_callingtns":"0","agi_dnid":"100365101","agi_rdnis":"unknown","agi_context":"my-voicer","agi_extension":"s","agi_priority":"1","agi_enhanced":"0.0","agi_accountcode":"","agi_threadid":"140450513794816","":""}
2021-8-5 20:17:46 - �[32minfo�[39m: 0000001 stepSetFailedVars
2021-8-5 20:17:46 - �[32minfo�[39m: 0000001 set RECOGNITION_RESULT=FAILED
2021-8-5 20:17:46 - �[32minfo�[39m: 0000001 stepGreeting
2021-8-5 20:17:46 - �[32minfo�[39m: 0000001 answer
2021-8-5 20:17:46 - �[32minfo�[39m: 0000001 o
2021-8-5 20:17:47 - �[32minfo�[39m: 0000001 stepRecord /tmp/e3bac18f-b369-4381-91b3-79abab2aee06
2021-8-5 20:17:47 - �[32minfo�[39m: 0000001 stepRecord start record
2021-8-5 20:17:50 - �[32minfo�[39m: 0000001 stepRecord end record
2021-8-5 20:17:50 - �[32minfo�[39m: 0000001 stepRecognize /tmp/e3bac18f-b369-4381-91b3-79abab2aee06.wav
2021-8-5 20:17:50 - �[32minfo�[39m: 0000001 file /tmp/e3bac18f-b369-4381-91b3-79abab2aee06.wav
options { developer_key: 'тутверныйключ',
file: '/tmp/e3bac18f-b369-4381-91b3-79abab2aee06.wav' }
res Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]:
{ body:
PassThrough {
_readableState: [Object],
readable: true,
domain: null,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
_writableState: [Object],
writable: false,
allowHalfOpen: true,
_transformState: [Object] },
disturbed: false,
error: null },
[Symbol(Response internals)]:
{ url: 'https://api.wit.ai/speech',
status: 200,
statusText: 'OK',
headers: Headers { [Symbol(map)]: [Object] },
counter: 0 } }
json { entities: {}, intents: [], text: 'ой', traits: {} }
2021-8-5 20:17:51 - �[32minfo�[39m: 0000001 text , intents=[], text=ой,
2021-8-5 20:17:51 - �[32minfo�[39m: 0000001 stepLookup ой
read file /etc/voicer/data/peernames.json
parsed [ { name: '104',
target: 'SIP/104',
variants:
[ 'мих светлана ивановна',
'светлана ивановна',
'светлана иванова',
.......
тутдлиннаяпортянкафайла
......
'не знаю' ] } ]
2021-8-5 20:17:51 - �[32minfo�[39m: 0000001 stepRepeatOnError Error: Lookup: not found in source
at Promise (/usr/lib/node_modules/voicer/apps/agi/source/fileSource.js:26:16)
at new Promise ()
at FileSource.find (/usr/lib/node_modules/voicer/apps/agi/source/fileSource.js:10:12)
at fileReader.readFile.then.then.then (/usr/lib/node_modules/voicer/apps/agi/source/fileSource.js:48:23)
at
2021-8-5 20:17:53 - �[32minfo�[39m: 0000001 --- fail, make next attempt --- current=2, total=2
2021-8-5 20:17:53 - �[32minfo�[39m: 0000001 stepRecord /tmp/e3bac18f-b369-4381-91b3-79abab2aee06
2021-8-5 20:17:53 - �[32minfo�[39m: 0000001 stepRecord start record
2021-8-5 20:17:57 - �[32minfo�[39m: 0000001 stepRecord end record
2021-8-5 20:17:57 - �[32minfo�[39m: 0000001 stepRecognize /tmp/e3bac18f-b369-4381-91b3-79abab2aee06.wav
2021-8-5 20:17:57 - �[32minfo�[39m: 0000001 file /tmp/e3bac18f-b369-4381-91b3-79abab2aee06.wav
options { developer_key: 'тутверныйключ',
file: '/tmp/e3bac18f-b369-4381-91b3-79abab2aee06.wav' }
res Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]:
{ body:
PassThrough {
_readableState: [Object],
readable: true,
domain: null,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
_writableState: [Object],
writable: false,
allowHalfOpen: true,
_transformState: [Object] },
disturbed: false,
error: null },
[Symbol(Response internals)]:
{ url: 'https://api.wit.ai/speech',
status: 200,
statusText: 'OK',
headers: Headers { [Symbol(map)]: [Object] },
counter: 0 } }
json { entities: {}, intents: [], text: 'давай', traits: {} }
2021-8-5 20:17:58 - �[32minfo�[39m: 0000001 text , intents=[], text=давай,
2021-8-5 20:17:58 - �[32minfo�[39m: 0000001 stepLookup давай
read file /etc/voicer/data/peernames.json
parsed [ { name: '104',
target: 'SIP/104',
variants:
[ 'мих светлана ивановна',
'светлана ивановна',
'светлана иванова',
.......
тутдлиннаяпортянкафайла
......
'не знаю' ] } ]
2021-8-5 20:17:58 - �[32minfo�[39m: 0000001 stepError Error: Lookup: not found in source
at Promise (/usr/lib/node_modules/voicer/apps/agi/source/fileSource.js:26:16)
at new Promise ()
at FileSource.find (/usr/lib/node_modules/voicer/apps/agi/source/fileSource.js:10:12)
at fileReader.readFile.then.then.then (/usr/lib/node_modules/voicer/apps/agi/source/fileSource.js:48:23)
at
2021-8-5 20:18:00 - �[32minfo�[39m: 0000001 stepFinish
2021-8-5 20:18:00 - �[32minfo�[39m: 0000001 -- hangup
2021-8-5 20:18:00 - �[32minfo�[39m: 0000001 stepFinish
2021-8-5 20:18:00 - �[32minfo�[39m: 0000001 -- close

Спасибо!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.