简体   繁体   English

可以在cordova应用中使用annyang进行语音识别吗?

[英]Is it possible to use annyang for speech recognition in cordova app?

I'm trying to use annyang for speech recognition in my cordova app. 我正在尝试在我的cordova应用程序中使用annyang进行语音识别。 I'm following Talater's and Alex's examples, but I cannot get it to work. 我正在遵循TalaterAlex的示例,但无法使其正常工作。

I noticed that it doesn't ask me for permission using my microphone. 我注意到它并没有要求我允许使用我的麦克风。

I'm testing the code in laptop's Chrome, not in device. 我正在笔记本电脑的Chrome中而不是在设备中测试代码。

My code is: 我的代码是:

<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World</title>
    <!-- <script src="js/speakClient.js"></script> -->
    <script src="http://cdnjs.cloudflare.com/ajax/libs/annyang/1.6.0/annyang.min.js"></script>
    <script src="js/annyang.min.js"></script>
</head>
<body>
    <div class="app">
        <h1>Apache Cordova</h1>
    </div>
</body>
<script type="text/javascript" src="js/annyang.js"></script>

This is my javascript code: 这是我的JavaScript代码:

// Language select
annyang.setLanguage('es-ES');

if (annyang) {

  var sayThis = function(repeat) {
    alert(repeat);
  }

  // Let's define a command.
  var commands = {
    '*repeat': sayThis
  };
  // Debug info for the console
  annyang.debug();

  // Initialize annyang with our commands
  annyang.init(commands);

  // Start listening.
  annyang.start();
}
else {
  alert("No annyang");
}

Please, tell me if I'm missing something (If not possible to make it work in cordova app, How can I use speech recognition in a cordova app meant to work in iPhone?) 请告诉我是否遗漏了一些东西(如果无法使其在Cordova应用程序中正常工作,如何在打算在iPhone上工作的Cordova应用程序中使用语音识别?)

I was able to get annyang.js to work in my Ionic (Cordova) app on Android devices. 我能够使annyang.js在Android设备上的Ionic(Cordova)应用程序中工作。 It's freaking amazing. 真是太神奇了。

The problem is that for the Android platform, Cordova bundles an Android browser by default. 问题在于,对于Android平台,Cordova默认情况下捆绑了Android浏览器。 However, Chrome is the only browser that currently supports Speech Recognition API. 但是,Chrome是当前唯一支持语音识别API的浏览器。 http://caniuse.com/#feat=speech-recognition http://caniuse.com/#feat=speech-recognition

The key is bundling a Chromium webview through Crosswalk . 关键是通过Crosswalk捆绑Chromium Webview Since Chrome is not available on iOS, this solution does not work with iOS. 由于Chrome在iOS上不可用,因此该解决方案不适用于iOS。 For Ionic applications, type in the following commands to add Crosswalk. 对于Ionic应用程序,键入以下命令以添加Crosswalk。

New Project: 新项目:

npm install ionic -g
ionic start my_app
cd my_app
ionic browser add crosswalk
ionic run android 

Previous Ionic Project: 先前的离子项目:

npm install ionic -g
cd existing_app
ionic browser add crosswalk
ionic run android

reference: http://blog.ionic.io/crosswalk-comes-to-ionic/ 参考: http : //blog.ionic.io/crosswalk-comes-to-ionic/

Then install "cordova-media-plugin" get permission to access Android's RECORD_AUDIO. 然后安装“ cordova-media-plugin”获取访问Android的RECORD_AUDIO的权限。 https://github.com/apache/cordova-plugin-media https://github.com/apache/cordova-plugin-media

cordova plugin add cordova-plugin-media

That's all. 就这样。

On a sidenote, you might want to try it out with an Angular wrapper for Annyang (version 1.5) available here: https://github.com/levithomason/angular-annyang 在旁注中,您可能想使用可用于Annyang的Angular包装器(1.5版)进行尝试, 网址为https : //github.com/levithomason/angular-annyang

All links mentioned above were accessed October 22, 2015 上述所有链接均于2015年10月22日访问

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

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