如何使用网络音频 API 设置采样率? [英] How to set up sample rate using web audio API?
本文介绍了如何使用网络音频 API 设置采样率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有由 webaudio API 生成的 blob 类型,但保存的文件必须具有高采样率.我怎样才能将它转换为较低的可能类似于 https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext 可以提供帮助吗?下面是一些代码示例:
I have blob type generated by webaudio API, but the file that is saved have to high sample rate. How can I convert it to lower maybe something like https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext can help? Here is some sample of code:
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);
};
推荐答案
我找不到控制采样率的方法,但这里有一种重新采样(上/下采样)的方法
I couldn't find a way to control the sample rate but here is a way to re-sample (up/down sampling)
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);
})
}
从这里提取:https://github.com/notthetup/resampler
这篇关于如何使用网络音频 API 设置采样率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文