SIGN UP

ASR

ASR module provides speech recognition capabilities. Audio stream can be sent to the ASR instance from a Call, Player or Conference. Language or dictionary should be passed to the VoxEngine.createASR function.

Add the following line to your scenario code to use the module:

 require(Modules.ASR);

All functions, events and classes of the module can be used only after this line.

Example

 require(Modules.ASR);

 var call,
 asr;

 // Inbound call
 VoxEngine.addEventListener(AppEvents.CallAlerting, function (e) {
		
		call = e.call;
		call.answer();
		call.addEventListener(CallEvents.Connected, handleCallConnected);
		call.addEventListener(CallEvents.Disconnected, VoxEngine.terminate);

	});

 // CallConnected event handler
 function handleCallConnected(callevent) {
		// Play prompt
		call.say("Hi, thanks for calling us! Please choose a color you like - red, blue, yellow or green ", Language.US_ENGLISH_FEMALE);
		// Init ASR - expect US English input and explicitly specified custom dictionary
		asr = VoxEngine.createASR(ASRLanguage.ENGLISH_US, ["red", "blue", "yellow", "green"]);
		// Handle ASREvents.CaptureStarted (fired when system detects voice input and start collecting data for ASR)
		asr.addEventListener(ASREvents.CaptureStarted, function(e) {
				call.stopPlayback();
			});
		// Handle recognition result
		asr.addEventListener(ASREvents.Result, function(asrevent) {
			asr.stop();
		    call.say("You've chosen "+asrevent.text+" color. Confidence is "+asrevent.confidence, Language.US_ENGLISH_FEMALE);
		    call.addEventListener(CallEvents.PlaybackFinished, VoxEngine.terminate);
		});
		// Send call media to ASR instance
		call.sendMediaTo(asr);
	}

functions

VoxEngine.createASR

VoxEngine.createASR(params: ASRParameters): ASR

Creates new speech recognizer and starts the recognition. Sources can later be attached using the Call.sendMediaTo method etc.

Parameters

  • ASR parameters. IMPORTANT: the lang parameter is required, the other parameters are optional.

Returns

Examples

request:

 require(Modules.ASR);

 var asr = VoxEngine.createASR({lang:ASRLanguage.ENGLISH_US, dict:["John", "Mike", "Matthew", "Cary"]});
 asr.addEventListener(ASREvents.Result, function(asrevent) {
		asr.stop();
	    if (asrevent.confidence > 50)  {
	    	call.say("Calling "+asrevent.text, Language.US_ENGLISH_FEMALE);
	    	call.addEventListener(CallEvents.PlaybackFinished, VoxEngine.terminate);
	    }
	});
 call.sendMediaTo(asr);

levenshtein_distance

levenshtein_distance(str1: String, str2: String): Number

Count the number of deletions, insertions, or substitutions required to transform str1 into str2. The number shows a measure of the similarity between two strings. It is also known as edit distance.

Parameters

  • str1:

    String

    First string

  • str2:

    String

    Second string

Returns

  • Return:

    Number