我有 data-uri 格式的音频数据,然后我将此 data-uri 转换为缓冲区现在我需要此缓冲区数据以新的采样率,当前音频数据为 44.1khz,我需要 16khz 的数据,如果我使用 RecordRTC API 录制了音频,如果我以低采样率录制音频,那么我的音频声音就会失真,所以我不知道如何重新采样我的音频缓冲区,
如果你们中的任何人对此有任何想法,请帮助我。
提前致谢:)
最佳答案
您可以使用 OfflineAudioContext 进行重采样,但您需要先将 data-uri 转换为 ArrayBuffer。此解决方案适用于浏览器,而不是服务器,因为在网络上发送质量较低的音频(较低的采样率)比在服务器上发送大量数据和重新采样要好。
// `source` is an AudioBuffer instance of the source audio
// at the original sample rate.
var TARGET_SAMPLE_RATE = 16000;
var offlineCtx = new OfflineAudioContext(source.numberOfChannels,
source.duration * TARGET_SAMPLE_RATE,
TARGET_SAMPLE_RATE);
// Play it from the beginning.
var offlineSource = offlineCtx.createBufferSource();
offlineSource.buffer = source;
offlineSource.connect(offlineCtx.destination);
offlineSource.start();
offlineCtx.startRendering().then((resampled) => {
// `resampled` contains an AudioBuffer resampled at 16000Hz.
// use resampled.getChannelData(x) to get an Float32Array for channel x.
});
关于node.js - 将音频缓冲区从 44100 重新采样到 16000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27598270/