简体   繁体   English

将Annyang.js语音识别与Angular.js集成

[英]Integrating Annyang.js speech recogniton with Angular.js

I'm attempting to integrate Annyang.js and Angular.js . 我正在尝试集成Annyang.jsAngular.js

I'm trying to make the result of Annyang.js bind (Angular style) with the DOM. 我正在尝试使Annyang.js的结果与DOM绑定(角度样式)。 Some ideas might be to use angular services like $watch, $apply, $digest, or to create a directive/factory/provider??? 有些想法可能是使用$ watch,$ apply,$ digest之类的角度服务,或者创建指令/工厂/提供者? I'm at a loss. 我很茫然。 Help would be appreciated. 帮助将不胜感激。

So far, it understands commands within the VoiceCtrl scope but it does not bind to $scope.said 到目前为止,它可以理解VoiceCtrl范围内的命令,但不绑定到$ scope。

Javascript: 使用Javascript:

var SpeechApp = angular.module('SpeechApp', []);

function VoiceCtrl($scope) {

  $scope.said='';

  $scope.helloWorld = function() {
    $scope.said = "Hello world!";
  }

  $scope.commands = {
    'hello (world)': $scope.helloWorld,
  };

  annyang.debug();
  annyang.init($scope.commands);
  annyang.start();
}

HTML: HTML:

<body ng-app="Voice" ng-controller="VoiceCtrl">
    <p>{{said}}</p>
</body>

It looks like you're missing a scope.$apply() . 好像您缺少一个scope.$apply() This is needed to allow angular to update all of your bindings as annyang.js is going to be working outside of angular context. 由于annyang.js将在angular上下文之外工作,因此需要允许angular更新所有绑定。

Try replacing your command with 尝试将命令替换为

'Hello (world)': function() {
    $scope.$apply($scope.helloWorld);
});

Also, you call the module "SpeechApp" in you JS and ng-app="Voice" in your HTML. 另外,您在JS中调用模块“ SpeechApp”,在HTML中调用ng-app =“ Voice”。

Suggest this HTML instead: 建议使用以下HTML:

  <body ng-app="SpeechApp">
    <div ng-controller="VoiceCtrl">
      <p>Hi: {{said}}</p>
    </div>
  </body>

http://plnkr.co/edit/QIWwhS?p=preview http://plnkr.co/edit/QIWwhS?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM