I've been trying to capture some audio from a user when he/she is talking for the past few days. Recently switched to master (commit acd1740f0b44064a0df0e4eecb5340af35869f72) in the hopes it would fix my problems but I just can't get it to work.
createReceiver returns a ReadableStream which should have a data event. It never logs the amount of bytes in that chunk so I have a feeling there is just no data coming through the stream at all. The code is running on a docker instance with the node:carbon image.
client.on('ready', () => {
let channel = client.channels.find('name', 'General');
channel.join().then(connection => {
const receiver = connection.createReceiver();
connection.on('speaking', (user, speaking) => {
console.log(user.username, 'speaking:', speaking);
if (speaking) {
const audioStream = receiver.createStream(user, {mode: 'pcm'});
audioStream.on('data', (chunk) => {
console.log(`Received ${chunk.length} bytes of data.`);
});
}
});
});
});
I've left VoiceReceivers in a sort of broken state while rewriting, I'll try and fix ASAP
Are there any workarounds at the moment for receiving voice data? I'm also running into the same problem.
Hi!
So I took another look, it actually looks like the code in discord.js is correct, there was a separate bug but it seems irrelevant to the issue here -- although please update your prism-media to 0.2.1!
A few days ago it was reported that Discord wouldn't actually send voice packets to bot until they started speaking, and I was able to reproduce this locally. A fix from Discord is coming soon, but for now, as a workaround, I'd suggest playing a very short file in each voice channel you join.
Thanks!
Discord.js voice now uses the v4 protocol which should fix this issue, see commit https://github.com/discordjs/discord.js/commit/08bbbe930144616338fc906ce5fc7a3e5725b670
I tried the example code posted above with the commit you linked and it still didn't emit any data events. I also tried playing a short audio file (500ms long) when the bot joined the voice channel, but it didn't help. Any ideas?
EDIT: Nevermind, installing FFMPEG through npm (ffmpeg-binaries), instead of relying on my previous installation from somewhere else, solved it. Maybe I should read the docs more carefully next time. Anyways, thanks for fixing this @hydrabolt ! :+1: :tada:
Has discord fixed the bug @amishshah said? My pcm files are still 0kb
Most helpful comment
I've left VoiceReceivers in a sort of broken state while rewriting, I'll try and fix ASAP