【问题标题】:Google SpeechRecognition and W3C Speech APIGoogle SpeechRecognition 和 W3C Speech API
【发布时间】:2014-03-17 15:48:41
【问题描述】:

我正在尝试使用 google WEB SPEECH API,但我遇到了 taht 的问题。 我是编程新手。所以我想做这样的东西 - https://www.google.com/intl/en/chrome/demos/speech.html

但是,当我使用 API 中的示例时,会出现错误。对象未定义...而且我不知道为什么。 我正在尝试使用此代码

 <script type="text/javascript">
    var recognition = new SpeechRecognition();
    recognition.onresult = function(event) {
      if (event.results.length > 0) {
        q.value = event.results[0][0].transcript;
        q.form.submit();
      }
    }
  </script>

  <form action="http://www.example.com/search">
    <input type="search" id="q" name="q" size=60>
    <input type="button" value="Click to Speak" onclick="recognition.start()">
  </form>

谁能帮我解决这个问题??? 谢谢。

【问题讨论】:

    标签: speech-recognition


    【解决方案1】:

    Google 并未完全实现 W3C API 规范,它们之间存在细微差别。对象名称是 webkitSpeechRecognition,而不是 SpeechRecognition。您可以在此处找到有关 webkit API 的示例:

    http://updates.html5rocks.com/2013/01/Voice-Driven-Web-Apps-Introduction-to-the-Web-Speech-API

    或这里:

    http://apprentice.craic.com/tutorials/37

    【讨论】:

    • 糟糕的代码,一半的代码和结束标签丢失。即使你填写了缺少的标签,它也不起作用。