0

私はApache Cordova用のビジュアルスタジオツールを使用してAndroidアプリを開発しています。私は新しいプロジェクトを開始し、GITのURLを使って音声認識プラグインを追加しました。Cordova 6で音声認識プラグインが動作していません

https://github.com/macdonst/SpeechRecognitionPlugin

それは正常にインストールされ、プロジェクトのビルドにも成功しています。私はアプリケーションを実行すると、以下のコードでは、音声認識プラグインの初期化の前に1つの警告を表示し、それ以降は2番目の警告に達しません。

function onDeviceReady() { 
     // Handle the Cordova pause and resume events 
     alert('test'); 
     recognition = new SpeechRecognition(); 
     alert('test 2'); 
     recognition.onresult = function (event) { 
      if (event.results.length > 0) { 
       alert(event.results[0][0].transcript); 
       q.value = event.results[0][0].transcript; 
       //q.form.submit(); 
      } 
     } 
     alert('test 2'); 
     document.addEventListener('pause', onPause.bind(this), false); 
     document.addEventListener('resume', onResume.bind(this), false); 

     // TODO: Cordova has been loaded. Perform any initialization that requires Cordova here. 
     var element = document.getElementById("deviceready"); 
     element.innerHTML = 'Device Ready'; 
     element.className += ' ready'; 
    }; 

プラグインの追加中に何か不足していますか?

+0

コンソールですべてのエラー?あなたはどのプラットフォームをテストしていますか? – Phonolog

+0

"認識"の前に "var"が見つからない。プロジェクトはデフォルトで厳密モードを使用します。 strictモードでは、変数を定義するために "var"が必要です。 –

答えて

0

長い間、同じ問題で立ち往生しました。 最後にそれを裂くことができました。トリックはcordova media pluginを追加することでした。次のように

作業コードは次のとおりです。

index.htmlを

<!DOCTYPE html> 
<html> 
    <head>   
     <meta name="format-detection" content="telephone=no"> 
     <meta name="msapplication-tap-highlight" content="no"> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> 
     <link rel="stylesheet" type="text/css" href="css/index.css"> 
     <title>Speech Recognition</title> 
    </head> 
    <body>  
     <br> 
     <br> 
     <br> 
     <br> 
     <br> 
     <br> 
     <br> 
     <br> 
     <form> 
     Click to speak <input type="button" value="speak" name="Download" id="speak" /> <br> 
     <input type="text" id="q" name="q" size=60> 
     </form> 

     <script type="text/javascript" src="js/jquery.js"></script> 
     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/app.js"></script> 
    </body> 
</html> 

app.js

$(document).ready(function() { 
    document.addEventListener("deviceready", onDeviceReady, false); 
}); 

var recognition; 
function onDeviceReady() { 

    $('#speak').click(function() { 
     recognition = new SpeechRecognition();   
     recognition.onresult = function(event) { 
      if (event.results.length > 0) { 
       console.log(event.results[0][0].transcript);     
       q.value = event.results[0][0].transcript; 
      } 
     };  
     recognition.start(); 
    }); 
} 
関連する問題