How to play a live stream of raw Opus packets (2‑byte BE length‑prefixed) in the browser (HTML/JS)? #1171
-
I’m capturing Opus frames live from a Discord Lavalink fork before encryption and dumping them to disk (and/or streaming them over WebSocket). Each packet is written as: 2‑byte big-endian length (N)
N bytes of Opus payload (48 kHz, ~20 ms per frame, Discord voice compatible) Example write logic (Kotlin, trimmed to the relevant part): override fun retrieveOpusFrame(buf: ByteBuf) {
// Duplicate the buffer to copy bytes for dumping
val ro = buffer.duplicate()
ro.flip()
val len = ro.remaining()
val bytes = ByteArray(len)
ro.get(bytes)
// Send frame to Discord
buf.writeBytes(buffer.flip())
// Dump frame to file: [2-byte big-endian length][Opus payload]
out.write((len ushr 8) and 0xFF)
out.write(len and 0xFF)
out.write(bytes)
} The resulting Example
I want to play this audio in real time in a plain HTML/JS front-end (Chrome/Firefox), ideally by streaming packets to the browser as they’re produced. Ideally, the browser would handle playback directly from raw Opus frames or small WebM segments; I want to avoid server-side conversion or transcoding. What I’ve tried
Main question:
Follow-ups:
Constraints
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
As this is a feature implemented in a fork of Lavalink (and thus, not our Lavalink), this is unsupported behaviour that we can't offer support with. I would advise contacting the owner of the fork you are using for support with this. |
Beta Was this translation helpful? Give feedback.
As this is a feature implemented in a fork of Lavalink (and thus, not our Lavalink), this is unsupported behaviour that we can't offer support with. I would advise contacting the owner of the fork you are using for support with this.