如何加载麦克风请求并保持其活动状态

How to load microphone request and keep it live

本文关键字:活动状态 请求 麦克风 何加载 加载      更新时间:2023-09-26

目前,我正在做一个项目,我需要处理来自用户的音频。我需要要求用户连接麦克风,以便我可以使用 x-webkit 语音初始化他的讲话 - 主要问题是用户需要单击按钮并在需要说话时始终说话 - 我希望浏览器询问用户网站是否可以使用 micrphone,如果用户接受请求,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);
}

快速入门:http://www.html5rocks.com/en/tutorials/webrtc/basics/