我正在尝试在我的 cordova 应用程序中使用 annyang 进行语音识别。我正在关注Talater's和 Alex's示例,但我无法让它工作。
我注意到它并没有要求我使用麦克风的许可。
我正在笔记本电脑的 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
以前的 ionic 项目:
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(版本 1.5)的 Angular 包装器,此处提供:https://github.com/levithomason/angular-annyang
上述所有链接均于 2015 年 10 月 22 日访问
关于javascript - 是否可以在 cordova 应用程序中使用 annyang 进行语音识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29450502/