piping from udp stream into an audio resource
hello! i've been trying to write a bot to pipe desktop audio to a discord bot over udp (i use linux so this is my jank workaround to not having screen share audio), and i've settled on using dgram to open a udp socket and running ffmpeg locally to push to it (the full command is
ffmpeg -f pulse -i default -f opus "udp://127.0.0.1:3756"
, and the local ip is fine for now since both the stream and bot are running on the same machine).7 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!other than that, here's the relevant code:
udpServer.js
app.js
sorry for multiple messages, discord doesn't like a lot of text :/
and if it would help to condense the code, i'll edit the above bits
i should also probably mention that i've tried returning a promise containing the received udp packets directly to the ReadableStream's i can fix the buffer issue, but i think that error will persist
if i change that, i think i get a type mismatch
yeah, the error does in fact persist
pull
function instead of the buffer jank, but this was just the last iteration of code before i decided to ask here. the current problem with the code is that it throws a typeerror on a method in the audioresource constructor when i try to set the inputType to opus:
finally, my packages + version numbers: (Node v21.4.0)
yeah there's gonna be a lot of that, sorry :/
i don't need to worry about the hash right now (im refactoring that later, right now there is only one user so it doesn't matter)
To debug your voice connection and player:
- Use
debug: true
when creating your VoiceConnection
and AudioPlayer
- Add an event listener to the <VoiceConnection> and the <AudioPlayer>:
- Add an error
listener to the stream you are passing to the resource:
Note: The <>
represents classes that need to be adapted to their respective name in your code
I was still getting debug messages without that beforehand?
and there are no debug messages before it crashes, even with the audioplayer option passed
and even if i do make it past that error (for now just by switching audio formats) i do still get a typeerror if i change that line you mentioned earlier:
I think msg is a buffer?
1. I still get a garbled stream if I use raw (and switch to s16le audio format in ffmpeg)
2. opus streams still throw that random error from the audioplayer constructor
i only ever get this far if i switch the streamtype to raw
or rather just not opus
so i still need to do that if the incoming data is opus as well?
oooh maybe
the acodec is correct, i think
i'm sorry to keep bringing this up, but it was really my original question: do i need to change the type of stream i'm inputting or something to avoid this constructor error:
i dont think i can do anything with streamtype opus as long as i get this before any audio is processed
update: i have switched to a readable instead of a readablestream to fix that issue, but now the readable stops getting called after 4 _read calls?
i'm gonna try and just simplify this program on another branch tomorrow, do you know a good program i can reference for piping a custom readable into discordjs? don't worry about it if not, but i think i'm fundamentally misunderstanding something about node streams and that would help more than another documentation tab at this point
@boppleopple Could you show current code?
sorry, i got absolutely ruined by a storm in maine a day after posting that, i lost power for 4 days and internet still hasn’t come back
(also i am a 6 hour drive away atm)
once i have internet back home i’ll work on it again
Sure