Reduce playing audio latency

Hi, I'm currently trying to convert an incoming audio stream (mulaw) to raw opus bitstream. Using ffmpeg and inputType as raw, I'm able to achieve it, but that introduces 3s of latency. Unfortunately, the incoming stream is real-time data, so this latency has to be reduced. I did manipulate around with ffmpeg, and got it to play a quiet popping noise under 1s (ofc that only happens when the stream audio is very loud). Here's my current ffmpeg setup (which doesn't work). Is there anything else I need to transform in stream for it to work?
// receiveRawStream is the raw mulaw Buffer
ffmpeg(receiveRawStream)
.inputOptions([
"-f mulaw",
"-ar 8000",
"-ac 1"
])
.outputOption([
"-c:a libopus",
"-f ogg",
"-ar 48000",
"-ac 2",
])
.on("error", (err)=>{
console.log(err);
})
.pipe(new opus.OggDemuxer(), {end: false}) // The demuxer is from "prism-media" package
.pipe(receiveffmpegStream);
/// receiveffmpegStream is the final stream before it's piped to createAudioResource (configured with StreamType.Opus)
// receiveRawStream is the raw mulaw Buffer
ffmpeg(receiveRawStream)
.inputOptions([
"-f mulaw",
"-ar 8000",
"-ac 1"
])
.outputOption([
"-c:a libopus",
"-f ogg",
"-ar 48000",
"-ac 2",
])
.on("error", (err)=>{
console.log(err);
})
.pipe(new opus.OggDemuxer(), {end: false}) // The demuxer is from "prism-media" package
.pipe(receiveffmpegStream);
/// receiveffmpegStream is the final stream before it's piped to createAudioResource (configured with StreamType.Opus)
Node Version: 20.12.2 DJS Version: 14.15.2
4 Replies
d.js toolkit
d.js toolkit7mo ago
- 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!
The Big E in Math -> Σ
I just found out that the stream is not configured with objectMode, which caused the issue. Even with that, the latency is still introduced, unlike the listener stream, which has latency less than 1s.
Fyphen
Fyphen7mo ago
It's likely a ffmpeg-related issue or your PC's performance issue There's nothing that I can help you with that problem
ThePedroo
ThePedroo7mo ago
The best would be using FFmpeg here
Want results from more Discord servers?
Add your server