简体   繁体   中英

WebAudioAPI - change SampleRate in Windows definitions

My sampleRate in AudioContext.SampleRate() is always 48khz. Then I change the definitions in windows, going to "recording devices" and change there the SampleRate of the Mic. But, with any reason to happen, the AudioContext.SampleRate() remains the same. Why? This value is related only to the device and not with the windows definitions?

The audio context sample rate is determined by the output device, not the input device. The input device is resampled to the output device rate.

You can use https://github.com/taisel/XAudioJS/blob/master/resampler.js

var resampler = new Resampler(44100, 48000, 1, 2229);

function startUsermedia(stream) {
    var input = audio_context.createMediaStreamSource(stream);
    recorder = audio_context.createScriptProcessor(2048);
    recorder.onaudioprocess = recorderProcess;
    recorder.connect(audio_context.destination);
}

function recorderProcess(e) {
    var buffer = e.inputBuffer.getChannelData(0);
    var resampled = resampler.resampler(buffer);
}

Note:
Creds for code: https://stackoverflow.com/a/30032095/1501285

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM