Created
January 9, 2017 09:27
-
-
Save aylarov/4e96a4520cedf24dc04fcb71f42115a8 to your computer and use it in GitHub Desktop.
Voximplant ASR example #4: voice bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Enable ASR module | |
require(Modules.ASR); | |
var call, asr; | |
// Answer inbound call | |
VoxEngine.addEventListener(AppEvents.CallAlerting, function (e) { | |
call = e.call; | |
call.addEventListener(CallEvents.Connected, onCallConnected); | |
call.addEventListener(CallEvents.Disconnected, VoxEngine.terminate); | |
call.answer(); | |
}); | |
function onCallConnected(callevent) { | |
// create ASR instance | |
asr = VoxEngine.createASR(ASRLanguage.ENGLISH_US); | |
// Recognition result | |
asr.addEventListener(ASREvents.Result, function (e) { | |
Net.httpRequestAsync("http://botservice.xyz/input?=" + encodeURIComponent(e.text)) | |
.then(function (result) { | |
// assuming that webservice returns text that bot should say | |
if (result.code == 200) { | |
call.say(result.text, Language.US_ENGLISH_FEMALE); | |
call.addEventListener(CallEvents.PlaybackFinished, function (e) { | |
call.removeEventListener(CallEvents.PlaybackFinished); | |
call.sendMediaTo(asr); | |
}); | |
} | |
}) | |
.catch(function (err) { | |
Logger.write(err); | |
}); | |
}); | |
// Speech captured - stop sending data to ASR | |
asr.addEventListener(ASREvents.SpeechCaptured, function (e) { | |
call.stopMediaTo(asr); | |
}); | |
call.say("Hi sir, how can I help you?", Language.US_ENGLISH_FEMALE); | |
call.addEventListener(CallEvents.PlaybackFinished, function (e) { | |
call.removeEventListener(CallEvents.PlaybackFinished); | |
call.sendMediaTo(asr); | |
}); | |
} |
You can stream media via Websockets for external recognition, see https://voximplant.com/blog/websocket-introduction
That looks very interesting. Thank you for quick reply.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK thanks for the reply. In that case is it possible to add any external ASR module. Can we do something like
call.sendMediaTo(externalAsr)
whereexternalAsr
can be any asr other than voximplant ASR ?