2014-01-09 56 views
1

我綜合https://github.com/poiuytrez/SpeechRecognizer的Android的PhoneGap SpeechRecognizer無法讀取屬性「speechrecognizer

我有以下錯誤

遺漏的類型錯誤:無法讀取屬性 '在文件中未定義speechrecognizer':/// android_asset/WWW /指數html的: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.xm升

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

enter image description here

+0

是您'的console.log(「設備已準備就緒」);'已記錄? – 2014-01-09 10:58:50

+0

沒有。沒有得到 – Nick

+0

你把你的cordova.js文件放在哪裏?什麼位置? – 2014-01-09 11:07:51

回答

0

剛剛的GOTO命令提示符下鍵入時: 科爾多瓦插件添加https://github.com/poiuytrez/SpeechRecognizer 比你寫的,那麼運行這個項目上面的代碼替換index.html的代碼後,生成項目& 完成。 我還對前幾天的工作,我做成功,如果你發現任何問題,讓我知道

感謝 阿倫·夏爾馬