From b6f62d15c4792bfb718ab4c95a78777c9e9b0192 Mon Sep 17 00:00:00 2001 From: Richard Abrich Date: Mon, 5 Oct 2015 22:07:03 -0400 Subject: [PATCH 1/2] Handle unexpected combined transcripts in Chrome on Android --- annyang.js | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/annyang.js b/annyang.js index 7b60633..7a32710 100644 --- a/annyang.js +++ b/annyang.js @@ -42,6 +42,8 @@ var debugState = false; var debugStyle = 'font-weight: bold; color: #00f;'; var pauseListening = false; + var combinedTranscript = ''; + var combinedTranscriptTimeoutId; // The command matching code is a modified version of Backbone.Router by Jeremy Ashkenas, under the MIT license. var optionalParam = /\s*\((.*?)\)\s*/g; @@ -158,6 +160,14 @@ }; recognition.onend = function() { + if (combinedTranscriptTimeoutId) { + if (debugState) { + root.console.log('Ignoring combined transcript: %c', combinedTranscript, debugStyle); + } + clearTimeout(combinedTranscriptTimeoutId); + combinedTranscriptTimeoutId = null; + combinedTranscript = ''; + } invokeCallbacks(callbacks.end); // annyang will auto restart if it is closed automatically and not by user action. if (autoRestart) { @@ -192,25 +202,36 @@ for (var i = 0; i Date: Mon, 5 Oct 2015 22:35:12 -0400 Subject: [PATCH 2/2] Enforce SpeechRecognition.maxAlternatives --- annyang.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/annyang.js b/annyang.js index 7a32710..dcdde7b 100644 --- a/annyang.js +++ b/annyang.js @@ -192,7 +192,9 @@ // Map the results to an array var SpeechRecognitionResult = event.results[event.resultIndex]; var results = []; - for (var k = 0; k