Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
185
Help us understand the problem. What is going on with this article?

More than 5 years have passed since last update.

@inouet

ブラウザからの音声入力を認識してテキスト化する (Web Speech API)

Chromeすごいわ。ブラウザだけでここまでできるとは。
こんな簡単なHTMLだけで音声認識→ テキスト化ができます。 日本語もOK。

speech.png

デモをこちらに起きました。
http://inouet.github.io/sample_html/001.speech_recognition.html

コード

<html>
<head>
  <meta charset="UTF-8" />
  <title>Web Speech API</title>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
window.SpeechRecognition = window.SpeechRecognition || webkitSpeechRecognition;
var recognition = new webkitSpeechRecognition();
recognition.lang = 'ja';

// 録音終了時トリガー
recognition.addEventListener('result', function(event){
    var text = event.results.item(0).item(0).transcript;
    $("#result_text").val(text);
}, false);

// 録音開始
function record()
{
    recognition.start();
}
</script>
</head>

<body>

<textarea id="result_text" cols="100" rows="10">
</textarea>
<br />
<input type="button" onClick="record()" value="録音開始" />
</body>
</html>

※ ローカルに保存したHTMLをchromeで表示したらうごかず。WEBサーバー経由で表示しないとだめみたい。ハマった。

参考ページ

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
185
Help us understand the problem. What is going on with this article?