Open ghost opened 8 years ago
I run the same piece of code and it does not fire on the first "record". Immediately hit the record button again and it works.
I've got the same issue as OP
Can you check with latest code?
are you calling start() somewhere? It won't fire onresult if you don't call start first
$scope.record = function () {
var recognition = new SpeechRecognition();
//recongni.continuous = true;
recognition.onresult = function (event) {
if (event.results.length > 0) {
$scope.recognizedText = event.results[0][0].transcript;
$scope.$apply()
}
};
recognition.onerror = function (error) {
$scope.recognizedText = JSON.stringify(error);
};
recognition.start();
};
And the android version where you are testing this?
My phone is Samsung Galaxy S6 Active with Android 5.1.1
Does it work the second time you call record? or never?
is the record function is being executed?
I fired up development again and started running on device again. (I had put it away for a while waiting for responses). Now it works perfectly on the first click of "record" button. It DOES NOT work on the second click and it hits the onerror event.
I question whether I have the latest source or not now. I use Visual Studio for this Cordova app - looking into making sure I have the latest code from you in my project.
The problem on the second call was fixed yesterday. I haven't increased the plugin version, so you'll have to uninstall and reinstall the plugin
Ok - I have the latest source code implemented. Getting more strange results. I click "record" works perfect. Click "record" again - on error, again - on error, again - on error ... the fourth click tries to work, then the fifth click works. Then repeat pattern.
Here is my controller: (Cordova and angular) app.controller('AskGenieCtrl', function($scope, AskGenieSvc) { var recognition; $scope.data = { speechText: 'how now brown cow' }; $scope.recognizedText = ''; $scope.parsedText = '';
Initialize();
$scope.speakText = function () {
TTS.speak({
text: $scope.data.speechText,
locale: 'en-EN',
rate: 1
}, function () {
}, function (reason) {
});
};
$scope.record = function () {
recognition.start();
};
function Initialize() {
recognition = new SpeechRecognition();
recognition.onresult = function (event) {
if (event.results.length > 0) {
var text = event.results[0][0].transcript;
$scope.recognizedText = text;
$scope.parsedText = parseText(text);
$scope.$apply();
}
};
recognition.onerror = function (error) {
alert(JSON.stringify(error));
};
}
function parseText(text) {
var wordCount = 1;
for (i = 0; i < text.length; i++) {
if (text.charAt(i) == " ") {
wordCount++;
}
}
var words = text.split(" ");
return "Words: " + wordCount + "... " + words;
}
});
this code never fires any alert, running on Android M Same result when tested on Android KitKat 4.4.4
var recognition = new SpeechRecognition();
recognition.onresult = function(event) { alert(event); if (event.results.length > 0) { alert(event.results[0][0].transcript) } }
If I alert recognition it is returned as "[object object ]" the issue is with "onresult"