How to properly play audio/webm;codecs=opus buffers to a voice channel sent via WebSocket?
Trying to broadcast a stream of audio buffers being recorded as
audio/webm;codecs=opus
using MediaRecorder
to a voice channel via a WebSocket
,
I know that the recording works because i can save the recording to a file and it plays in the browser.
Here's my code:
4 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!I imagine you'll at least want to specify
inputType: StreamType.WebmOpus
for your resource
beyond this if it's still not properly playing audio, please share the logs from debugging your AudioPlayer
and VoiceConnection
and just to make absolutely sure, might as well generate a dependency report:guide: Getting Started: Introduction - Debugging Dependencies
read more
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
Hi @duck thanks for replying, here's what happened:
After I set
inputType:StreamType.WebmOpus
it gave me the following error which i've encountered before, the audioPlayer
debug info is included in this log.
Dependency report
One more thing, when i save my recording as an audio.webm
file and i play it through discord, using createAudioResource("path/to/audio.webm")
it plays normally...
WebSocket server code
Basically it receives the recorded audio from a WS client (called insider) and then forwards it to other WS clients (the listeners) like in the first snippet.
im pushing data everytime the socket receives from server, but the read()
is required, however i don't see what code to put there since im directly calling push()
on ws.addEventListener("message")
How can i fix this particular error?