我想在 javascript 中对音频缓冲区进行下采样。我正在使用 OfflineAudioContext,但输出音频质量明显低于原始音频(44100Hz)。在javascript中是否有比这更高质量的音频重采样的解决方案:
var sampleRate = 44100;
var outSampleRate = 16000;
var durationInSamples = audioBuffer441k.length;
var o = new OfflineAudioContext(1, durationInSamples*outSampleRate/sampleRate, outSampleRate);
var b = o.createBuffer(1, durationInSamples, sampleRate);
var buf = b.getChannelData(0);
for (var i = 0; i < durationInSamples; i++) {
buf[i] = audioBuffer441k[i];
}
var source = o.createBufferSource();
source.buffer = b;
source.connect(o.destination);
source.start(0);
o.startRendering();
o.oncomplete = function(audiobuffer16k) {
console.log("done resampling!!");
console.log(audiobuffer16k.renderedBuffer);
//do something with resampled audio
}