30分チャレンジ〜8日目〜
kazuma.です。
今日の30分チャレンジは「音声プログラミング」です。
昨日はweb上にアップして音声入力を試してみました。
今日は音声によりコード入力してみました。
if文を書いてみます。
Javascript部分のみ
var reco = new WebSpeechRecognition(); reco.statusText('status'); reco.statusImage('status_img'); reco.finalResults('input_field'); reco.continuous = true; reco.onEnd = function() { var ifmoji = "if( "; var elsemoji = "else( "; var toji = "){"; var equal = "="; var text01; //if (reco.final_transcript != '') { // input_field.form.submit(); if(reco.final_transcript.length == 1){ if(document.form01.point1.value.length > 0) { text01 = document.form01.point1.value; text01 = "" + reco.final_transcript; }else{ text01 = reco.final_transcript; } document.form01.point1.value += text01; reco.final_transcript = ''; } if(reco.final_transcript == 'もし') { if(document.form01.point1.value.length > 0) { text01 = document.form01.point1.value; text01 = "" + ifmoji; }else{ text01 = ifmoji; } document.form01.point1.value += text01; reco.final_transcript = ''; } if(reco.final_transcript == 'Else' ||reco.final_transcript == 'えるす') { if(document.form01.point1.value.length > 0) { text01 = document.form01.point1.value; text01 = "" + elsemoji; }else{ text01 = elsemoji; } document.form01.point1.value += text01; reco.final_transcript = ''; } if(reco.final_transcript == 'かっことじ') { if(document.form01.point1.value.length > 0) { text01 = document.form01.point1.value; text01 = "" + toji; }else{ text01 = toji; } document.form01.point1.value += text01; reco.final_transcript = ''; } if(reco.final_transcript == 'Equal') { if(document.form01.point1.value.length > 0) { text01 = document.form01.point1.value; text01 = "" + equal; }else{ text01 = equal; } document.form01.point1.value += text01; reco.final_transcript = ''; } // } };
コメント化しているところは不要箇所ですね。
reco.final_transcript
このコードですが、ここに音声入力した最後の言葉が入るそうです。
で、変数nやaなど一文字の変数は.lengthで計算し1の場合そのまま入力されるようになっています。
Voice Programming.
まぁそりゃ手で打つ方が早いわな。
ちょっと面白いけど( ✧Д✧) pic.twitter.com/SixkfW92Cs
— Kazuma. (@kazumalab) 2015, 7月 17
こんな感じでおっそいですが認識できているようです。
リアルタイム読み込みできればいいんですが。
まぁ今は初期ということでお許しください( ̄  ̄)
あ、ちなみに今回アップしているサイトです。
voiceProgram
では。