【问题标题】:How to convert wav file into 8000hz using Nodejs如何使用 Nodejs 将 wav 文件转换为 8000hz
【发布时间】:2020-06-11 02:12:01
【问题描述】:

我尝试使用 nodejs 将语音 wav 文件转换为文本,但它显示如下错误:

错误:

data: '{\n "error": "此 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); });
}

【问题讨论】:

  • 那么,您需要重新采样您的 WAV 文件吗?
  • 是的,我需要将我的 audio.wav 文件转换为 8000hz
  • 你有什么理由不为此使用 FFmpeg 吗? ffmpeg -i input.wav -ar 8000 output.wav

标签: node.js nodes ibm-watson speech-to-text


【解决方案1】:

我不确定您是否已经探索过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

【讨论】:

    猜你喜欢
    • 2016-06-19
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    • 2021-06-13
    • 1970-01-01
    • 2017-09-28
    • 2011-06-17
    • 1970-01-01
    相关资源
    最近更新 更多