HTML5音频录制无法使用外部麦克风

HTML5 Audio Recording Not Working External Microphone

本文关键字:外部 麦克风 音频 HTML5      更新时间:2023-09-26

我正在使用getUserMedia来访问Chrome(版本28.0.1500.72 m)中的用户麦克风。当用户使用带内部扬声器的内部麦克风时,我可以录制和回放他们的输入。

一旦我插入usb麦克风耳机,我就无法再记录用户的输入。我已经在隐私和内容设置下切换了chrome设置中的设备。所以chrome确实看到了新插入的麦克风。我重新启动了chrome,并在插入麦克风后再次尝试。仍然没有用户输入。

提前感谢。

以下是我正在使用的当前代码。

    window.AudioContext = window.AudioContext||window.webkitAudioContext;
    var html5Recorder;
    var audioContext = new AudioContext();
    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
    if(navigator.getUserMedia){
        navigator.getUserMedia({audio:true},handleAudioStream, audioError)
    }else{
        console.log('Use Flash')
    }
    function handleAudioStream(stream){
        var mediaStream = audioContext.createMediaStreamSource(stream);
        mediaStream.connect( audioContext.destination );
        html5Recorder = new HTML5Recorder(mediaStream);
        html5Recorder.stop();
        html5Recorder.clear();
    }
    function audioError(error){
        console.log(error);
    }
    function record(){
        html5Recorder.record();
    }
    function stopRecording(){
        html5Recorder.stop();
        html5Recorder.exportWAV(function(e){
            console.log(e);
            console.log(window.URL.createObjectURL(e));
           document.getElementById('audio1').src =  window.URL.createObjectURL(e);
            HTML5Recorder.forceDownload(e);
        });
    }

这是我使用的当前chrome构建中的一个错误(28)。铬金丝雀效果很好。

您能检查两个音频设备的采样率吗?

存在一个现有的错误,即非默认麦克风只有在采样率与默认麦克风相同时才能工作:https://code.google.com/p/chromium/issues/detail?id=164058.

此外,您使用的是OSX还是Linux?错误中的注释使它看起来应该在Windows上修复。

尝试选择USB麦克风作为默认麦克风。Chrome不管理音频设备,它总是使用默认的麦克风。