如何使用naudiodon portaudio解决输出欠流错误?

问题描述 投票:2回答:1

我正在写一个小的node.js程序,它将能够在一个选定的音频设备上播放wav声音文件.声音开始得很好,但它在文件结束前停止。

这是我的代码。

const fs = require("fs");
const wav = require("wav");
const portAudio = require("naudiodon");

const ao = new portAudio.AudioIO({
    outOptions: {
        channelCount: 2,
        sampleFormat: portAudio.SampleFormat24Bit,
        sampleRate: 44100,
    }
});

const name = "myfile.wav";
const file = fs.createReadStream(`./sounds/${name}`);

const reader = new wav.Reader();

reader.on("format", () => {
    reader.pipe(ao);
    ao.start();
});

file.pipe(reader);

process.on("SIGINT", ao.quit);

当我修改 highWaterMark 的选择 fs.createReadStream它稍微改变了声音中的切割位置,但它从来没有去,直到它的结束。portAudio status - output underflow 日志错误。

谢谢你的帮助!

node.js stream wav portaudio
1个回答
0
投票

我也遇到过类似的错误,我的解决方案是手动写入AudioIO流,而不是使用管道命令。

因此,我的解决方案是手动写入AudioIO流,而不是使用管道命令。

reader.on("format", () => {
    reader.pipe(ao);
    ao.start();
});

你会使用

ao.start();
reader.on("data",chunk=>ao.write(chunk));

输出下溢一般不是问题,但为了避免这个问题,我在播放每个文件之前都初始化了一个新的PortAudio实例,然而这只适用于你不在乎轻微延迟的情况。

© www.soinside.com 2019 - 2024. All rights reserved.