jmprzz
jmprzz
DIAdiscord.js - Imagine an app
Created by jmprzz on 8/14/2024 in #djs-voice
How to properly play audio/webm;codecs=opus buffers to a voice channel sent via WebSocket?
How can i fix this particular error?
error: Did not find the EBML tag at the start of the stream
at onwrite (native:1:1)
at native:1:1
at _transform (/Users/Main/Desktop/weaver/node_modules/prism-media/src/core/WebmBase.js:49:9)
at native:1:1
at writeOrBuffer (native:1:1)
at native:1:1
at ondata (native:1:1)
at emit (native:1:1)
at addChunk (native:1:1)
at readableAddChunk (native:1:1)
error: Did not find the EBML tag at the start of the stream
at onwrite (native:1:1)
at native:1:1
at _transform (/Users/Main/Desktop/weaver/node_modules/prism-media/src/core/WebmBase.js:49:9)
at native:1:1
at writeOrBuffer (native:1:1)
at native:1:1
at ondata (native:1:1)
at emit (native:1:1)
at addChunk (native:1:1)
at readableAddChunk (native:1:1)
11 replies
DIAdiscord.js - Imagine an app
Created by jmprzz on 8/14/2024 in #djs-voice
How to properly play audio/webm;codecs=opus buffers to a voice channel sent via WebSocket?
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")
11 replies
DIAdiscord.js - Imagine an app
Created by jmprzz on 8/14/2024 in #djs-voice
How to properly play audio/webm;codecs=opus buffers to a voice channel sent via WebSocket?
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.
// websocket server
const server = Bun.serve({
fetch(req, server) {

// checking for "listener" in headers
const headers = Object.fromEntries(req.headers.entries())
const isListener = headers["sec-websocket-protocol"] === "listener"

// upgrade the request to a WebSocket
// add data to the client so it can be referenced
if (server.upgrade(req, {
data: {
headers,
listener: isListener,
id: isListener ? listeners.length + 1 : 0
}
})) {
return;
}
return new Response("Upgrade failed", { status: 500 });
},

websocket: {
// if client is a listener, subscribe it to "listeners" topic, else is the insider client.
open: (ws) => {
if (ws.data.listener) {
listeners.push(ws.data)
ws.subscribe('listeners')
} else {
insider = ws.data
}
updateConsole()
},
close: (ws, code, reason) => {
// a listener disconnected
if (ws.isSubscribed("listeners") || ws.data.listener) {
ws.unsubscribe('listeners')
listeners = listeners.filter(l => l.id !== ws.data.id)
}
else {
// terminate script
end("Insider disconnected")
}
},
async message(ws, data) {
try {
// if this option is enabled, write recording to a file
if (writer) {
writer.write(data)
writer.flush()
}

if (listeners.length > 0) {
// broadcast recording
server.publish("listeners", data)
}

// for debugging
buffer = data
totalBytes += data.length

updateConsole()
}
catch (e) {
console.error(e)
end("Error in server message")
}
}
}
});
// websocket server
const server = Bun.serve({
fetch(req, server) {

// checking for "listener" in headers
const headers = Object.fromEntries(req.headers.entries())
const isListener = headers["sec-websocket-protocol"] === "listener"

// upgrade the request to a WebSocket
// add data to the client so it can be referenced
if (server.upgrade(req, {
data: {
headers,
listener: isListener,
id: isListener ? listeners.length + 1 : 0
}
})) {
return;
}
return new Response("Upgrade failed", { status: 500 });
},

websocket: {
// if client is a listener, subscribe it to "listeners" topic, else is the insider client.
open: (ws) => {
if (ws.data.listener) {
listeners.push(ws.data)
ws.subscribe('listeners')
} else {
insider = ws.data
}
updateConsole()
},
close: (ws, code, reason) => {
// a listener disconnected
if (ws.isSubscribed("listeners") || ws.data.listener) {
ws.unsubscribe('listeners')
listeners = listeners.filter(l => l.id !== ws.data.id)
}
else {
// terminate script
end("Insider disconnected")
}
},
async message(ws, data) {
try {
// if this option is enabled, write recording to a file
if (writer) {
writer.write(data)
writer.flush()
}

if (listeners.length > 0) {
// broadcast recording
server.publish("listeners", data)
}

// for debugging
buffer = data
totalBytes += data.length

updateConsole()
}
catch (e) {
console.error(e)
end("Error in server message")
}
}
}
});
11 replies
DIAdiscord.js - Imagine an app
Created by jmprzz on 8/14/2024 in #djs-voice
How to properly play audio/webm;codecs=opus buffers to a voice channel sent via WebSocket?
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...
11 replies
DIAdiscord.js - Imagine an app
Created by jmprzz on 8/14/2024 in #djs-voice
How to properly play audio/webm;codecs=opus buffers to a voice channel sent via WebSocket?
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.
44 | let result;
45 | while (result !== TOO_SHORT) {
46 | try {
47 | result = this._readTag(chunk, offset);
48 | } catch (error) {
49 | done(error);
^
error: Did not find the EBML tag at the start of the stream
at onwrite (native:1:1)
at native:1:1
at _transform (/Users/Main/Desktop/weaver/node_modules/prism-media/src/core/WebmBase.js:49:9)
at native:1:1
at writeOrBuffer (native:1:1)
at native:1:1
at ondata (native:1:1)
at emit (native:1:1)
at addChunk (native:1:1)
at readableAddChunk (native:1:1)

state change:
from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"idle","resource":false,"stepTimeout":false}
44 | let result;
45 | while (result !== TOO_SHORT) {
46 | try {
47 | result = this._readTag(chunk, offset);
48 | } catch (error) {
49 | done(error);
^
error: Did not find the EBML tag at the start of the stream
at onwrite (native:1:1)
at native:1:1
at _transform (/Users/Main/Desktop/weaver/node_modules/prism-media/src/core/WebmBase.js:49:9)
at native:1:1
at writeOrBuffer (native:1:1)
at native:1:1
at ondata (native:1:1)
at emit (native:1:1)
at addChunk (native:1:1)
at readableAddChunk (native:1:1)

state change:
from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"idle","resource":false,"stepTimeout":false}
Dependency report
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.17.0
- prism-media: 1.3.5

Opus Libraries
- @discordjs/opus: 0.9.0
- opusscript: not found

Encryption Libraries
- sodium-native: not found
- sodium: 3.0.2
- libsodium-wrappers: 0.7.14
- tweetnacl: not found

FFmpeg
- version: 6.0
- libopus: yes
--------------------------------------------------
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.17.0
- prism-media: 1.3.5

Opus Libraries
- @discordjs/opus: 0.9.0
- opusscript: not found

Encryption Libraries
- sodium-native: not found
- sodium: 3.0.2
- libsodium-wrappers: 0.7.14
- tweetnacl: not found

FFmpeg
- version: 6.0
- libopus: yes
--------------------------------------------------
11 replies
DIAdiscord.js - Imagine an app
Created by SkyLissh on 5/23/2024 in #djs-voice
Error installing @discordjs/opus
No description
3 replies