TL; DR: The app wasn't working because I was using it on Android 6.0 and needed to manually grant microphone access permission.
Here's the story: I set out to develop an Ionic app that utilizes speech recognition with this plugin: https://github.com/macdonst/SpeechRecognitionPlugin
But for some reason, it just wouldn't cooperate?
To start off, I created a new Ionic project:
ionic start cordova-speech blank
I then navigated into the newly created folder and added the plugin:
cordova plugin add https://github.com/macdonst/SpeechRecognitionPlugin
Next, I included the android platform.
This is what my HTML file looked like:
<body ng-app="starter">
<ion-pane ng-controller="AppCtrl">
<ion-content class="padding">
<button class="button button-full button-positive" ng-click="record()">
Record
</button>
<div class="card">
<div class="item item-text-wrap">
{{recognizedText}}
</div>
</div>
</ion-content>
</ion-pane>
</body>
As for my app.js file:
angular.module('starter', ['ionic'])
.controller('AppCtrl', function($scope) {
$scope.recognizedText = '';
$scope.record = function() {
alert("step1");
var recognition = new SpeechRecognition();
alert("step2");
recognition.onresult = function(event) {
alert("step3");
if (event.results.length > 0) {
$scope.recognizedText = event.results[0][0].transcript;
$scope.$apply();
}
};
recognition.start();
alert("step4");
};
});
In order to debug (as debugging this feature in the browser isn't possible), I inserted some alerts into the code. However, upon pressing the record button, only the first and second alert would show up. It appears that there is a problem with the onresult section. What could be causing this issue?
I am running Android 6.0
After performing an adb logcat, here are the results:
...
UPDATE: I tried installing
cordova plugin add cordova-plugin-chrome-apps-audiocapture --save
cordova plugin add org.apache.cordova.media
Some sources suggested removing the
<uses-permission android:name="android.permission.RECORD_AUDIO" />
from both the speechrecognition and cordova media plugins, but unfortunately, this did not resolve the issue. Although the fourth alert now executes, it still omits alert 3, indicating a lingering problem within the onresult function.