我尝试使用nodejs将语音wav文件转换为文本,但显示如下错误:
错误:
数据:'{\ n“错误”:“此8000hz音频输入需要窄带 模式。“ \ n}',
代码:
let directory = `File Directory`;
let dirbuf = Buffer.from(directory);
let files = fs.readdirSync(directory);
// Create the stream.
// Pipe in the audio.
files.forEach(wav_files => {
//how can i convert that wav file into 8000hz and use that same wav file for speech to text convert
fs.createReadStream(wav_files).pipe(recognizeStream);
recognizeStream.on('data', function(event) { onEvent('Data:',event,wav_files); });
}
答案 0 :(得分:0)
我不确定您是否已经探索过wav软件包。但是我创造了这样的作弊行为:
const fs = require('fs');
const WaveFile = require('wavefile').WaveFile;
let wav = new WaveFile(fs.readFileSync("source.wav"));
// do it like this
wav.toSampleRate(8000);
// or like following way with your choice method
// wav.toSampleRate(44100, {method: "cubic"});
// write new file
fs.writeFileSync("target-file.wav", wav.toBuffer());
对于完整的示例运行克隆node-cheat wav-8000hz,先运行node wav.js
,然后运行npm i wavefile
。