代码之家  ›  专栏  ›  技术社区  ›  hakkikonu

如何停止文本区域的语音识别?

  •  0
  • hakkikonu  · 技术社区  · 7 年前

    我有一个 <textarea> 我不想允许我的用户在任何设备上使用语音识别。

    我试过这个JQuery方法,但是我不能在我的IPhone或Chrome桌面上阻止语音识别。

    $('#answerText').bind('webkitspeechchange',function(e) {
        console.log("Speech recognition is not allowed");
        e.preventDefault();
    });
    
    0 回复  |  直到 7 年前
        1
  •  0
  •   Neo    6 年前

    你可以尝试清空 <textarea> 元素,并在文本中显示消息,不使用语音识别。

    $('#answerText').bind('webkitspeechchange',function(e) {
    $('#answerText').text("Speech recognition is not allowed. Please use the keyboard");
    e.preventDefault();
    });
    

    这样,用户可以使用语音识别,但结果不会显示在文本区域。相反,他们会收到信息,知道你想让他们使用键盘。

    但正如Rory McCrossan所说,我不确定您是否希望实现这一点,特别是在有特殊需求的用户需要的地方。