我正在尝试在Pulseaudio设备上播放几个音频流(一个又一个)。但是,实际上似乎只有第一个流可以到达设备。
该代码侦听Discord语音通道,并在每次有人讲话时创建原始音频流(PCM)。然后,它将流通过转码器( sox-stream )传递到带有名为 speaker
的模块的音频设备:conn.on('speaking', (user, speaking) => {
if (speaking) {
console.log(`I'm listening to ${user}`);
const audioStream = receiver.createPCMStream(user);
// This works for every time someone speaks.
audioStream.pipe(generateOutputFile()); // generateOutputFile returns a writeStream to a file.
// This only works for the first time someone speaks after the script is initiated.
audioStream.pipe(
sox({ // sox-stream package
global: { G: true , guard: true, 'no-dither': true },
input: {type: 'raw', e:'signed', bits: 32, endian: 'little', rate: 48000, channels: 1},
output: {type: 'raw', bits: 16, endian: 'little', e: 'signed', rate: 44100 , channels:2},
}))
.pipe(speaker); // speaker package with libpulse back-end
}
});
扬声器定义为:
const speaker = new Speaker({
channels: 2, // 2 channels
bitDepth: 16, // 16-bit samples
sampleRate: 44100, // 44,100 Hz sample rate
device: 'test1'
});
有趣的部分是,我添加了audioStream.pipe(generateOutputFile());
并将原始音频写入pcm文件,这适用于每个流。甚至audioStream.pipe(sox(options)).pipe(generateOutputFile())
都适用于每个流。这使我相信问题是speaker
不能按我的意愿处理多个流。
关于为什么发生这种情况的任何指示都将非常有帮助!