cordova-plugin-speechrecognition
cordova-plugin-speechrecognition copied to clipboard
startListening "matches" option returns too many results (setting "matches: 1" does not work)
Problem: startListening()
almost always returns 5 matches, despite setting matches: 1
.
Question: could someone please offer advice about how to restrict the output to return just a single/best match value?
Here is some sample code to illustrate how I have set the matches option:
function startRecognition(inputFieldId){
window.plugins.speechRecognition.startListening(function(result){
// Show the result in the corresponding input field
document.getElementById(inputFieldId).setAttribute("value", result);
}, function(err) {
console.error(err);
}, {
language: "en-US", matches: 1, prompt: "", showPopup: false
});
};
Note: modifying the other options, like prompt
works fine, but modifying matches
does nothing.
@pdubuc, result is an array. Try result[0]. I think the first value is the best, I am using it like that.
This is happening to me as well on Android (not tested on iOS).
During partial results sometimes you have higher confidence later in the array list (which I would've assumed would get sent to the first index).
The final results only have a single confidence score (instead of 5), so the wacky thing is that you get 5 results and 5 scores on the very last partial message, once you get to the final result you get 5 results and only the first score in the confidence array.
It feels like it's a bug with the SpeechRecognizer class in general since I can see the "matches: 1" being sent to the startListening command, but android is ignoring it.
So it looks like we'll have to use result[0] until the SDK gets an update :(
I'm using cordova-android 7.1.1 (sdk 27).