在ASP.NET aspx页面中使用Google的Webkit语音?

时间:2015-04-17 07:18:03

标签: c# asp.net google-chrome speech-recognition speech

我尝试在ASP.NET Aspx页面中使用Google Webkit Speech API:

<asp:TextBox class="chat-to-ai-textbox" ID="chatbox" runat="server" placeholder="Type or Speak"></asp:TextBox>

并添加了代码行:

protected void Page_Load(object sender, EventArgs e)
{
      chatbox.Attributes.Add("x-webkit-speech", "x-webkit-speech");
}

我还添加了以下脚本来检测浏览器对Speech的支持:

<script>
        if (document.createElement("input").webkitSpeech === undefined) {
            alert("Speech input is not supported in your browser.");
        }
</script>

但是,在运行Chrome时,我没有看到语音按钮/选项来启动识别,浏览器显示我的“浏览器不支持”错误我编写的脚本。我做错了什么?

1 个答案:

答案 0 :(得分:1)

  

不推荐使用x-webkit-speech输入字段属性。请改用JavaScript API。

为此目的使用Github项目:https://github.com/Daniel-Hug/speech-input

示例:http://daniel-hug.github.io/speech-input/

使用:

包括speech-input.css和speech-input.js 在输入字段中添加si-input类。 使用si-wrapper类将输入包装在a中。 添加一个带有si-btn类的按钮作为输入的兄弟。对于默认样式,请使用以下示例中的按钮标记:

<div class="si-wrapper">
    <input type="text" class="si-input" placeholder="What's up?">
    <button class="si-btn">
        speech input
        <span class="si-mic"></span>
        <span class="si-holder"></span>
    </button>
</div>

enter image description here