Skip to content

Instantly share code, notes, and snippets.

@aylarov
Created December 16, 2016 15:52
Show Gist options
  • Save aylarov/23eaad038462eb00ba9558be5729cd3c to your computer and use it in GitHub Desktop.
Save aylarov/23eaad038462eb00ba9558be5729cd3c to your computer and use it in GitHub Desktop.
Voximplant ASR example #2: streaming commands
// 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, ["Yellow", "Green", "Red", "Blue", "White", "Black"]);
// Recognition result
asr.addEventListener(ASREvents.Result, function (e) {
call.say("You have chosen " + e.text + " color, confidence is " + e.confidence, Language.US_ENGLISH_FEMALE);
});
// Speech captured - stop sending data to ASR
asr.addEventListener(ASREvents.SpeechCaptured, function (e) {
call.stopMediaTo(asr);
});
call.say("Choose your color", Language.US_ENGLISH_FEMALE);
call.addEventListener(CallEvents.PlaybackFinished, function (e) {
call.removeEventListener(CallEvents.PlaybackFinished);
call.sendMediaTo(asr);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment