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 toolkit2mo 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
Fyphen5w 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
ThePedroo5w ago
The best would be using FFmpeg here
Want results from more Discord servers?
Add your server
More Posts
Automod issue againhttps://sourceb.in/M8SCsPB8Y6 - full code https://sourceb.in/UI1i8qlcEI - is the problematic part ofBot responding from a button, and answer with a text and two buttons moreHi! I have a problem on my code.....I dont know how to do this: When only the **Staff** click on theCannot read data and .toJSONC:\Users\Bernardo\Desktop\berrie\main.js:37 for (const command of commands) { commandArray.pregistration stepper/wizardI want to make a registration stepper/wizard how do i create this using Discord.js i want to have a If I receive two messages on the same channel, I want to be able to retrieve both of them separatelyI pressed the wrong button. I am reposting. Sorry for the long title. I would like to do exactly whaIf I receive two messages on the same channel, I want to be able to retrieve both of them separatelySorry for the long title. I have been doing JS for a year or two and I am still a beginner. I would An invalid token was provided.I reseted my token and i did put in my config.json ```json { "token_secret":"" } ``` ```js consChange Role icon (Emoji)I want to change the icon for a specific roll with an emoji. I'm trying to do that, but I'm getting How can i add no prefix system into my bot??I have to create a full no prefix system along with no prefix add remove list command how can i do tBot responding with 2 or 3 messages instead of 1 after being not used for a whilehi, anyone can help me? i have an guildMemberAdd event to welcome my new members on server which sen