【问题标题】:Only enable mic once on runtime仅在运行时启用一次麦克风
【发布时间】:2015-10-11 16:17:18
【问题描述】:

我正在使用 webkitSpeechRecognition (https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html#dfn-onspeechstart) 向网络应用添加语音输入。

每次我启动recognition.start(); (recognition = new webkitSpeechRecognition()) 时,都会出现这个要求允许使用麦克风的弹出窗口:

用户将需要在应用程序的整个生命周期中多次使用麦克风,我只希望他们必须给予一次许可。

我怎样才能让它在网络应用加载时显示?

【问题讨论】:

标签: javascript microphone


【解决方案1】:

使用 JQuery:

$(document).ready(function(){ recognition.start(); });

使用纯JS:

document.addEventListener("DOMContentLoaded", function(event) { recognition.start(); });

【讨论】:

  • 这不会停止权限的请求
  • 没有权限请求是不能激活麦克风的。您可以做的就是继续在后台运行。并在需要时读出数据。但是,这仍会提示用户加载页面。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-06
  • 1970-01-01
  • 1970-01-01
  • 2015-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多