我正在使用angular-webspeech-directive
这是HTML代码:
TestBed asdfasdfDebugger $scope.speech:{{speech|json}}
这是角度speechapp.js
(function() { var app; app = angular.module("plunker", ["jonniespratley.angularWebSpeechDirective"]); app.controller("MainCtrl", function($scope) { return $scope.speech = { maxResults: 25, continuous: true, interimResults: true }; $scope.$on('onresult', function() {console.log( "---->speech.interimResults<----" );}); $scope.test=function(){ console.log( "---->speech.interimResults<----" ); } $scope.$digest(); $scope.$watch('$scope.speech.interimResults', function() {console.log( "---->speech.interimResults<----" ); }, true); $scope.$watch('speech.interimResults', function(newVal, oldVal) { //do something here like get the text input value and send to api //after speaking even the value of speech.intermResults change this does not get triggered. return console.log(newVal); }, true); }); }).call(this);
我想要发生的是每当用户完成对Mic的说话时,我都可以获得输入txt,这样我就可以发布处理文本内容.我需要获取文本输入的内容并能够将其发送到API,但是我找不到指令的onresult事件的钩子.
这是观看scope.speech的好方法,我尝试了$ scope.$ watch看看$ scope.speech是否已更改,但它无法正常工作.在此先感谢您的帮助.
不要$scope
用于引用范围变量$watch
.而不是
$scope.$watch('$scope.speech.interimResults', function () { console.log("---->speech.interimResults<----"); }, true);
你应该写
$scope.$watch('speech.interimResults', function () { console.log($scope.speech.interimResults); }, true);