简体   繁体   中英

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. I'm following Talater's and Alex's examples, but I cannot get it to work.

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.

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:

// 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?)

I was able to get annyang.js to work in my Ionic (Cordova) app on Android devices. It's freaking amazing.

The problem is that for the Android platform, Cordova bundles an Android browser by default. However, Chrome is the only browser that currently supports Speech Recognition API. http://caniuse.com/#feat=speech-recognition

The key is bundling a Chromium webview through Crosswalk . Since Chrome is not available on iOS, this solution does not work with iOS. For Ionic applications, type in the following commands to add 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/

Then install "cordova-media-plugin" get permission to access Android's RECORD_AUDIO. 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

All links mentioned above were accessed October 22, 2015

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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