I am looking for a way to do speech recognition using ionic framework . I want to run an app in both ios and android device. Currently i am providing a web view in both ios and android and have a common code base . I want to include speech recognition feature to it and fetch the output of speech .
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It looks like you have at least a couple options if you search around for "cordova speech recognition" on Google and if you look at the plugin repo at Apache's Cordova site.
Here's two quick ones I found.
- https://github.com/macdonst/SpeechRecognitionPlugin (Android & iPhone)
- https://github.com/floatinghotpot/cordova-plugin-iflyspeech (Android & iPhone)
The key here is that Ionic Framework is built on Cordova, so really you want a Cordova plugin for speech recognition.
回答2:
I was stuck at the same point. Then I found a url where I got a solution. As per as url they followed a cordova plugin
. So you need to follow these steps:
1 - add Cordova plugin
cordova plugin add https://github.com/macdonst/SpeechRecognitionPlugin
2 - add TTS plugin
cordova plugin add cordova-plugin-tts
3 - implementation of plugin code
app.controller('AppCtrl', function($scope) {
$scope.data = {
speechText: ''
};
$scope.recognizedText = '';
$scope.speakText = function() {
window.TTS.speak({
text: $scope.data.speechText,
locale: 'en-GB',
rate: 0.7
}, function () {
// Do Something after success
}, function (reason) {
// Handle the error case
alert(reason+"");
});
};
$scope.record = function() {
var recognition = new SpeechRecognition();
recognition.onresult = function(event) {
if (event.results.length > 0) {
$scope.recognizedText = event.results[0][0].transcript;
$scope.$apply()
}
};
recognition.start();
};
});
Enjoy your code time:)
回答3:
You can use ng-speech-recognition AngularJS directive, it is working with ionic Framework:
ng-speech-recognition