目前,我正在开展一个项目,我需要处理来自用户的音频。我需要让用户连接一个麦克风,这样我就可以用 x-webkit speech 初始化他的讲话 - 主要问题是用户需要点击一个按钮并在他需要说话时总是说话 - 我想要浏览器询问用户网站是否可以使用麦克风,如果用户接受请求,x-webkit 将工作并保持在线状态。 如何在不强制用户点击按钮的情况下让 x-webkit 语音保持实时?
谢谢!
最佳答案
我认为你需要 Webrtc getusermedia`
//get audio
navigator.getUserMedia({audio:true}, gotStream);
.
//display audio
function gotStream(stream) {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext();
// Create an AudioNode from the stream
var mediaStreamSource = audioContext.createMediaStreamSource(stream);
// Connect it to destination to hear yourself
// or any other node for processing!
mediaStreamSource.connect(audioContext.destination);
}
关于javascript - 如何加载麦克风请求并使其保持事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19098709/