node.js - 将音频缓冲区从 44100 重新采样到 16000

标签 node.js audio buffer web-audio-api

我有 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/

相关文章:

objective-c - 如何在macOS objective-c 中播放本地文件?

javascript - 以从服务器接收到的字节形式播放 wav 文件

javascript - IE加载6个音频后html5音频返回错误MEDIA_ERR_SRC_NOT_SUPPORTED

c - 加载标准输入缓冲区

java - Java 中用于音频的循环 ShortBuffer

database - Oracle NCLOB 问题

node.js - pg-promise:使用 pgp.helpers.update 更新包含数组文本列的行

node.js - 返回 promise 值 `then`

node.js - 如何在while循环中执行 Nightmare js

Javascript继承对象覆盖其他继承对象