我们有两个人在不同频道讲话的录音。我正在尝试node.js here的官方文档。首先,我收到有效负载大小超过最大限制的错误。
ubuntu@ip-xxxx:~/nodejs-docs-samples/speech$ node recognize.js async /home/ubuntu/output.wav
(node:18306) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Request payload size exceeds the limit: 10485760 bytes.
然而,文档刚刚提到了记录长度方面的限制,而不是文件大小。这是link
有没有解决方法呢?
另外,我尝试使用较小的文件大小并得到配置错误:
ubuntu@ip-xxx:~/nodejs-docs-samples/speech$ node recognize.js async /home/ubuntu/output2.wav
(node:18291) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Invalid Configuration, Does not match Wav File Header.
Wav Header Contents:
Encoding: LINEAR16
Channels: 2
Sample Rate: 16000.
Request Contents:
Encoding: linear16
Channels: 1
Sample Rate: 16000.
我不确定API是否允许使用2声道音频输入,因为我在文档中找不到任何此类配置。但是,我发现this link建议将音频拆分为各个频道并单独使用。以编程方式执行此操作的推荐方法是什么?
答案 0 :(得分:3)
我最终采用了这种方法
sox
这是一个将文件拆分为通道的辅助函数
function splitFileToChannels (fileName) {
let output = {
channel1: `${fileName}_channel1.wav`,
channel2: `${fileName}_channel2.wav`
};
let channel1Command = `sox ${fileName} ${fileName}_channel1.wav remix 1`;
let channel2Command = `sox ${fileName} ${fileName}_channel2.wav remix 2`;
return Promise.all([
childProcess.execAsync(channel1Command),
childProcess.execAsync(channel2Command)
])
.then(() => {
return output;
});
}
另外,在分割为频道之前,我必须先将mp3
文件转换为wav
格式。