Translate

2017年4月6日木曜日

monacaでcordovaプラグインを使って音声入力をする

必要なプラグイン

https://github.com/macdonst/SpeechRecognitionPlugin

必要なプラン gold以上

inputフィールドに、音声でテキストを入れたい。
キーボードのマイクボタンでは小さくて押しづらいという話があったので、cordovaプラグインを使って実装。

function voicesearch(){      

    var micOptions = {
          language : "ja-JP",
          matches : 1,
        }
        window.plugins.speechRecognition.startListening( micSuccess,  micError,  micOptions);      
}
   
   
    function micSuccess(result){
        $("#searchword").val(result) ;//jquery使ってます
        search();
    }
   
    function micError(result) {
        //alert("error : " + result) ;
    }


html

<input type="search" id="searchword">
<ons-button onclick="voicesearch()" >音声入力</ons-button>


0 件のコメント:

コメントを投稿