如何在Android的Chrome中读取纯原始麦克风数据?

时间:2019-01-05 08:20:41

标签: android google-chrome audio webrtc getusermedia

我的目标是捕获通过Android中的Chrome运行的网页中的高质量音乐音频。 为此,我一直在摆弄getUserMedia API。

我正在将以下约束传递给get媒体:

constraints = {echoCancellation: {exact: false},
                autoGainControl: {exact: false}};
navigator.mediaDevices.getUserMedia({audio: constraints}).then(record_processor);

以下是我如何处理在getusermedia回调中接收的流:

function record_processor(stream){
console.log('in record_processor');
context = new AudioContext();
var source  = context.createMediaStreamSource(stream);
buffer_size = 1024*16;
var processor = context.createScriptProcessor(buffer_size,1,1);
source.connect(processor);
processor.connect(context.destination);
sample_rate = context.sampleRate;
console.log('sample rate: ' + sample_rate);

total_iterations = ((TOTAL_RECORDING_TIME*sample_rate)/(1000*buffer_size));
console.log('total iterations: ' + total_iterations);

counter = 0;
var chunks = [];
processor.onaudioprocess = function (e){
  var buffer = new Float32Array(e.inputBuffer.getChannelData(0));
  chunks.push(buffer);

  //console.log('buffer: ', buffer);
  console.log(counter);


  counter +=1;
  if(counter > total_iterations){
    console.log('iterations complete');
    context.close();
    //stopStreaming();
    console.log('audiochunks: ', chunks);
    data = mergeBuffers(chunks, chunks.length*buffer_size);

    console.log('data', data);
    wav_view = encodeWAV(data);

    var audioBlob = new Blob([wav_view], {type: 'audio/wav'});
    //forceDownload(audioBlob, 'recording.wav');
    console.log(audioBlob);
    get_song(audioBlob, sample_rate);
  }
};

}

问题在于,这使我得到了预处理,而不是原始音频数据。显然,Chrome应用了一些背景噪音检测功能,并试图消除任何持续时间超过半秒的图案。

请问我如何要求Chrome不要对音频应用任何过滤/预处理,并向我提供麦克风硬件接收到的纯原始数据?

以下是我正在接收的麦克风数据的波形和频谱图:

chrome output's waveform Chrome output's Spectogram

0 个答案:

没有答案