我有由webaudio API生成的blob类型,但保存的文件必须具有高采样率。 如何将它转换为更低可能像https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext之类的东西可以帮助? 以下是一些代码示例:
var xhr = new XMLHttpRequest();
/* HERE IS SOME CONVERTATION TO LOWER RATE */
var fd = new FormData();
fd.append("randomname", bigBlob);
xhr.open("POST",url,false);
xhr.send(fd);
xhr.onload=function(e) {
alert(e.target.responseText);
};
答案 0 :(得分:2)
答案 1 :(得分:2)
我找不到控制采样率的方法,但这是一种重新采样(上/下采样)的方法
function reSample(audioBuffer, targetSampleRate, onComplete) {
var channel = audioBuffer.numberOfChannels;
var samples = audioBuffer.length * targetSampleRate / audioBuffer.sampleRate;
var offlineContext = new OfflineAudioContext(channel, samples, targetSampleRate);
var bufferSource = offlineContext.createBufferSource();
bufferSource.buffer = audioBuffer;
bufferSource.connect(offlineContext.destination);
bufferSource.start(0);
offlineContext.startRendering().then(function(renderedBuffer){
onComplete(renderedBuffer);
})
}