Skip to content

Instantly share code, notes, and snippets.

@aylarov
Created January 9, 2017 09:27
Show Gist options
  • Select an option

  • Save aylarov/4e96a4520cedf24dc04fcb71f42115a8 to your computer and use it in GitHub Desktop.

Select an option

Save aylarov/4e96a4520cedf24dc04fcb71f42115a8 to your computer and use it in GitHub Desktop.
Voximplant ASR example #4: voice bot
// 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);
});
}
@aylarov

aylarov commented Apr 16, 2020

Copy link
Copy Markdown
Author

Because of call.sendMediaTo(asr);

@dyutibhaba

Copy link
Copy Markdown

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) where externalAsr can be any asr other than voximplant ASR ?

@aylarov

aylarov commented Apr 16, 2020

Copy link
Copy Markdown
Author

You can stream media via Websockets for external recognition, see https://voximplant.com/blog/websocket-introduction

@dyutibhaba

Copy link
Copy Markdown

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