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

cyn*_*7us 6 javascript jquery html5 webkit

目前,我正在开展一个项目,我需要使用来自用户的音频.我需要要求用户连接一个微型电话,这样我就可以用x-webkit语音初始化他的演讲 - 主要问题是用户需要点击一个按钮并在他需要发言时说话 - 我想要浏览器询问用户网站是否可以使用micrphone,如果用户接受请求,x-webkit将工作并保持活动状态.如何在不强迫用户点击按钮的情况下使x-webkit语音保持不变?

谢谢!

Pix*_*ded 2

我认为你需要 Webrtc getusermedia`

//get audio    
navigator.getUserMedia({audio:true}, gotStream);
Run Code Online (Sandbox Code Playgroud)

//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);
}
Run Code Online (Sandbox Code Playgroud)

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