我正在寻找一种使用离子框架进行语音识别的方法。我想在ios和android设备上运行一个应用程序。 目前我在ios和android中都提供了一个Web视图,并且有一个共同的代码库。我想在其中加入语音识别功能并获取语音输出。
答案 0 :(得分:4)
我被困在同一点上。然后我找到了url,我得到了一个解决方案。根据网址,他们跟随cordova plugin
。所以你需要按照以下步骤操作:
1 - 添加Cordova插件
cordova plugin add https://github.com/macdonst/SpeechRecognitionPlugin
2 - 添加TTS插件
cordova plugin add cordova-plugin-tts
3 - 插件代码的实现
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();
};
});
享受您的代码时间:)
答案 1 :(得分:0)
你可以使用ng-speech-recognition AngularJS指令,它正在使用离子框架: