没有数据管道时如何插入静音 pcm 数据 [英] How to insert silence pcm data when there is no data piping in

查看:30
本文介绍了没有数据管道时如何插入静音 pcm 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究 Discord.js 语音接收器,我需要它在没有实际音频数据进入时通过写入静默数据包来连续发送 PCM 音频数据.

I'm currently working on Discord.js voice receiver and I need it to continuously send PCM audio data by writing silent packet when there is no actual audio data coming in.

我之前发现了这个讨论,但我不明白/不知道如何当没有实际数据包进入时插入静默数据包

I found this discussion before but I don't understand/know how to insert silent packets when there's no actual packet is coming in

接收方代码:

const r = connection.receiver.createStream(user, {
  mode: 'pcm',
  end: 'manual'
});
// Nothing is piped when user is not talking
// u.stream is PassThrough stream
r.pipe(u.stream);

首选方法是创建一个扩展 PassThrough 或任何流类型的类,以便我可以将接收器数据通过管道传输给它,并且当没有数据通过(来自接收器)时,它将发送静默数据包(使用 'pcm-silence' 包),看起来像这样:

Prefered approach is to make a class that extends PassThrough or any stream type so I can pipe the receiver data to it and when theres is no data coming through (from the receiver), it will send silent packet (generated using 'pcm-silence' package) and will look something like this:

const fs = require('fs');
const passStream = new SilentStreamClass();
const r = connection.receiver.createStream(user, {
  mode: 'pcm',
  end: 'manual'
});
r.pipe(passStream);
passStream.pipe(fs.createWriteStream('./user.pcm'));
// When user is not talking, it will filled with silent packet.

提前致谢!

推荐答案

在网上搜索了一段时间后,我找到了一个 npm 包 audio-mixer 来混合多个 pcm 音频流,它会静音没有要处理的数据时的数据包,效果很好!

After some time searching the internet, I found a npm package audio-mixer to mix multiple pcm audio stream and it will pipe silent packet when theres no data to process, worked like a charm!

这篇关于没有数据管道时如何插入静音 pcm 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆