TheUntitledGoose
TheUntitledGoose
DIdiscord.js - Imagine ❄
Created by TheUntitledGoose on 1/14/2025 in #djs-questions
Discord.js voice resampling issues.
Hate how the v2 has ogg decoder but 1.3.5, latest, doesn't. It's either you get only ogg or you get a build that works but doesn't convert to ogg. Weird
20 replies
DIdiscord.js - Imagine ❄
Created by TheUntitledGoose on 1/14/2025 in #djs-questions
Discord.js voice resampling issues.
No description
20 replies
DIdiscord.js - Imagine ❄
Created by TheUntitledGoose on 1/14/2025 in #djs-questions
Discord.js voice resampling issues.
2.0.0-alpha0 I think. It was used in the discord.js voice examples since they used OggDemuxer or something, so I just still have that.
20 replies
DIdiscord.js - Imagine ❄
Created by TheUntitledGoose on 1/14/2025 in #djs-questions
Discord.js voice resampling issues.
I've updated the code to both have a 48khz decoder and a resampler to 16khz, however I still get
RangeError [ERR_OUT_OF_RANGE]: The value of "sourceEnd" is out of range. It must be >= 0 && <= 3. Received 8
at validateOffset (node:buffer:123:3)
at Buffer.compare (node:buffer:940:5)
at Decoder._transform (/mnt/x/discord_date_bot/node_modules/prism-media/dist/opus/Decoder.js:19:19)
at Transform._write (node:internal/streams/transform:175:8)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at Writable.write (node:internal/streams/writable:337:10)
at AudioReceiveStream.ondata (node:internal/streams/readable:809:22)
at AudioReceiveStream.emit (node:events:529:35)
at addChunk (node:internal/streams/readable:368:12)
RangeError [ERR_OUT_OF_RANGE]: The value of "sourceEnd" is out of range. It must be >= 0 && <= 3. Received 8
at validateOffset (node:buffer:123:3)
at Buffer.compare (node:buffer:940:5)
at Decoder._transform (/mnt/x/discord_date_bot/node_modules/prism-media/dist/opus/Decoder.js:19:19)
at Transform._write (node:internal/streams/transform:175:8)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at Writable.write (node:internal/streams/writable:337:10)
at AudioReceiveStream.ondata (node:internal/streams/readable:809:22)
at AudioReceiveStream.emit (node:events:529:35)
at addChunk (node:internal/streams/readable:368:12)
opusStream = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 2000,
},
});

const prism = await import('prism-media');
const pcmStream = new prism.opus.Decoder({
rate: 16000,
channels: 1,
frameSize: 320,
});


const opusDecoder = new prism.opus.Decoder({
rate: 48000, // Discord 48kHz
channels: 2,
frameSize: 960
});

const ffmpeg = new prism.FFmpeg({
args: [
'-loglevel', 'debug',
'-f', 's16le', // Input format
'-ar', '48000', // Input rate
'-ac', '2', // Input channels
'-i', 'pipe:0', // Input from pipe
'-f', 's16le', // Output format
'-ar', '16000', // Output rate
'-ac', '1', // Output channels (mono)
'pipe:1' // Output to pipe
]
});
// I'm not too sure about this FFmpeg command. The stackoverflow comment I found says this is okay?

opusStream.pipe(opusDecoder).pipe(ffmpeg)
opusStream = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 2000,
},
});

const prism = await import('prism-media');
const pcmStream = new prism.opus.Decoder({
rate: 16000,
channels: 1,
frameSize: 320,
});


const opusDecoder = new prism.opus.Decoder({
rate: 48000, // Discord 48kHz
channels: 2,
frameSize: 960
});

const ffmpeg = new prism.FFmpeg({
args: [
'-loglevel', 'debug',
'-f', 's16le', // Input format
'-ar', '48000', // Input rate
'-ac', '2', // Input channels
'-i', 'pipe:0', // Input from pipe
'-f', 's16le', // Output format
'-ar', '16000', // Output rate
'-ac', '1', // Output channels (mono)
'pipe:1' // Output to pipe
]
});
// I'm not too sure about this FFmpeg command. The stackoverflow comment I found says this is okay?

opusStream.pipe(opusDecoder).pipe(ffmpeg)
Seems like a problem with decoding the discord output stream? Is discord not 48khz?
20 replies
DIdiscord.js - Imagine ❄
Created by TheUntitledGoose on 1/14/2025 in #djs-questions
Discord.js voice resampling issues.
Thank you for the answer, I'll try that and see how it goes.
20 replies
DIdiscord.js - Imagine ❄
Created by TheUntitledGoose on 1/14/2025 in #djs-questions
Discord.js voice resampling issues.
I have little knowledge on how audio decoding/encoding works.
20 replies