我已整合https://github.com/poiuytrez/SpeechRecognizer
我得到以下错误
未捕获的TypeError:无法在file:///android_asset/www/index.html阅读未定义的属性'speechrecognizer':20
的index.html
<!DOCTYPE html>
<html>
<head>
<title>Speech Recognition plugin demo</title>
<script type="text/javascript" src="cordova-2.2.0.js"></script>
<script type="text/javascript" src="SpeechRecognizer.js"></script>
</head>
<body>
<script type="text/javascript">
function onDeviceReady(){
console.log("Device is ready");
}
function recognizeSpeech() {
var maxMatches = 5;
var promptString = "Speak now"; // optional
var language = "en-US"; // optional
window.plugins.speechrecognizer.startRecognize(function(result){
alert(result);
}, function(errorMessage){
console.log("Error message: " + errorMessage);
}, maxMatches, promptString, language);
}
// Show the list of the supported languages
function getSupportedLanguages() {
window.plugins.speechrecognizer.getSupportedLanguages(function(languages){
// display the json array
alert(languages);
}, function(error){
alert("Could not retrieve the supported languages : " + error);
});
}
document.addEventListener("deviceready", onDeviceReady, true);
</script>
<button onclick="recognizeSpeech();">Start recognition</button>
<button onclick="getSupportedLanguages();">Get Supported Languages</button>
</body>
</html>
config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android"
id="com.phonegap.plugins.speech" version="1.0.0">
<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
<name>SpeechRecognizer</name>
<description>Recognizes speech input</description>
<license>MIT</license>
<js-module src="SpeechRecognizer.js" name="SpeechRecognizer">
<clobbers target="plugins.speechrecognizer" />
</js-module>
<platform name="android">
<source-file src="SpeechRecognizer.java" target-dir="src/com/phonegap/plugins/speech" />
<source-file src="LanguageDetailsChecker.java" target-dir="src/com/phonegap/plugins/speech" />
<config-file target="res/xml/config.xml" parent="/*">
<feature name="SpeechRecognizer" >
<param name="android-package" value="com.phonegap.plugins.speech.SpeechRecognizer"/>
</feature>
</config-file>
</platform>
</plugin>
答案 0 :(得分:0)
只需在命令提示符下输入: cordova插件添加https://github.com/poiuytrez/SpeechRecognizer 而不是建立你的项目&amp;之后用您编写的上述代码替换index.html代码,而不是简单地运行该项目 那已经完成了。 我也在前几天工作,如果你发现任何问题我成功完成了,请告诉我
由于 Arun Sharma