node.js - 将 8kHz mulaw 转换为 PCM 16kHz
问题描述
我试图以 8kHz mulaw 接收来自 Twilio 的对话流,并且我想将其转换为 16kHz PCM 以进行某些处理(不支持 8kHz mulaw 格式),我尝试了这种方法但没有成功:
- 将字符串有效负载转换为 base64 缓冲区。
- 使用此包将缓冲区转换为 Uint8Array:buffer-to-uint8array。
- 使用此 pacakge: alawmulaw 将 Uint8Array 转换为Int16Array。
- 然后使用 wav 库编写结果。
按照这个过程,我仍然无法获得有效的音频文件,有人能告诉我我做错了什么吗?或指导我实现这一目标?
解决方案
我很幸运使用 WaveFile 库(https://www.npmjs.com/package/wavefile)
const wav = new WaveFile();
wav.fromScratch(1, 8000, '8m', Buffer.from(payload, "base64"));
wav.fromMuLaw();
// You can resample.
wav.toSampleRate(16000);
// You can write this straight to a file (will have the headers)
const results = wav.toBuffer();
// Or you can access the samples without the WAV header
const samples = wav.data.samples;
希望有帮助!
推荐阅读
- python - 如何根据 .csv 上的数据将视频分类?
- firebase - Firebase 云运行教程 权限被拒绝
- c# - 为什么在 ImageSource 上设置 TemplateBinding 会引发 KeyNotFoundException?
- linux - 在 HTML 文件中打印 ls -la
- c - 不明白为什么我不能释放一个数组
- flutter - 未处理的异常:无法加载资产:使用 AudioCache
- python - 如何阅读特定 Outlook 文件夹中的 Outlook 电子邮件
- json - 在 Flutter 中从 JSON 转换的列表对象中为变量赋值
- perl - 如何计算 Perl 中出现的奇数次?
- python - 如何在python中创建多个分隔文件?