receiving audio from a user and playing it with ffplay

This is my code:
let connection = joinVoiceChannel({
adapterCreator: message.guild.voiceAdapterCreator,
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
selfDeaf: false,
selfMute: true
});

let subscription = connection.receiver.subscribe(message.author.id, {
autoDestroy: false,
emitClose: false
});

const ffplay = exec('ffplay -');

subscription.pipe(ffplay.stdin)
let connection = joinVoiceChannel({
adapterCreator: message.guild.voiceAdapterCreator,
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
selfDeaf: false,
selfMute: true
});

let subscription = connection.receiver.subscribe(message.author.id, {
autoDestroy: false,
emitClose: false
});

const ffplay = exec('ffplay -');

subscription.pipe(ffplay.stdin)
It looks like the subscription is giving audio but the ffplay is not playing it.
10 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Nounejm
NounejmOP2y ago
sorry, its [email protected] and also @discordjs/[email protected] its all defined, no errors, ffplay is installed and its working out of the code node version is v19.7.0
SethGamer1223
SethGamer12232y ago
Is it possible that when your bot joins the channel it mutes its self
Nounejm
NounejmOP2y ago
selfDeaf is for the bot to hear, def true selfMute is for the bot to talk, def false its also getting the packets, ffplay is just not playing them I see i am getting ignored
duck
duck2y ago
this isn't ffplay support, but I imagine it doesn't support playing an opus packet stream you can utilize the opus.Decoder class from prism-media (which @discordjs/voice depends on) to decode the opus packet stream to pcm https://amishshah.github.io/prism-media/opus.Decoder.html
Nounejm
NounejmOP2y ago
ty
let connection = joinVoiceChannel({
adapterCreator: message.guild.voiceAdapterCreator,
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
selfDeaf: false,
selfMute: true
});

let subscription = connection.receiver.subscribe(message.author.id, {
autoDestroy: false,
emitClose: false
});

let decoder = new opus.Decoder({
channels: 2,
frameSize: 960,
rate: 48000
})

let ffplay = exec('ffplay -')

subscription.pipe(decoder).pipe(ffplay.stdin)
let connection = joinVoiceChannel({
adapterCreator: message.guild.voiceAdapterCreator,
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
selfDeaf: false,
selfMute: true
});

let subscription = connection.receiver.subscribe(message.author.id, {
autoDestroy: false,
emitClose: false
});

let decoder = new opus.Decoder({
channels: 2,
frameSize: 960,
rate: 48000
})

let ffplay = exec('ffplay -')

subscription.pipe(decoder).pipe(ffplay.stdin)
this is the updated version, it does actually pop up a ffplay window but the audio is just bunch of random noises, "whitenoice"?
duck
duck2y ago
you'll probably need some extra ffplay args to specify the format of what you're playing but this is leaving the scope of this channel
Nounejm
NounejmOP2y ago
All fixed, thank you One more thing, can the bot recrod the whole voice room and hot just 1 user?
duck
duck2y ago
there is no method for receiving all users in the voice channel as 1 stream if that's what you're asking you can call <VoiceReceiver>.subscribe() as many times as you want
Nounejm
NounejmOP2y ago
So i have to add a logic for when the user leaves channel, joins channel, types the command? cool
Want results from more Discord servers?
Add your server