[英]Is it possible to use annyang for speech recognition in cordova app?
我正在尝试在我的cordova应用程序中使用annyang进行语音识别。 我正在遵循Talater和Alex的示例,但无法使其正常工作。
我注意到它并没有要求我允许使用我的麦克风。
我正在笔记本电脑的Chrome中而不是在设备中测试代码。
我的代码是:
<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>
这是我的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");
}
请告诉我是否遗漏了一些东西(如果无法使其在Cordova应用程序中正常工作,如何在打算在iPhone上工作的Cordova应用程序中使用语音识别?)
我能够使annyang.js在Android设备上的Ionic(Cordova)应用程序中工作。 真是太神奇了。
问题在于,对于Android平台,Cordova默认情况下捆绑了Android浏览器。 但是,Chrome是当前唯一支持语音识别API的浏览器。 http://caniuse.com/#feat=speech-recognition
关键是通过Crosswalk捆绑Chromium Webview 。 由于Chrome在iOS上不可用,因此该解决方案不适用于iOS。 对于Ionic应用程序,键入以下命令以添加Crosswalk。
新项目:
npm install ionic -g
ionic start my_app
cd my_app
ionic browser add crosswalk
ionic run android
先前的离子项目:
npm install ionic -g
cd existing_app
ionic browser add crosswalk
ionic run android
参考: http : //blog.ionic.io/crosswalk-comes-to-ionic/
然后安装“ cordova-media-plugin”获取访问Android的RECORD_AUDIO的权限。 https://github.com/apache/cordova-plugin-media
cordova plugin add cordova-plugin-media
就这样。
在旁注中,您可能想使用可用于Annyang的Angular包装器(1.5版)进行尝试, 网址为 : https : //github.com/levithomason/angular-annyang
上述所有链接均于2015年10月22日访问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.