Advice for audio lag?

So I have an application and utilizes meteor.setInterval and meteor.setTimeout to play audio files.

Issue is, more often than I’d like it to, the sound files don’t play ‘on time’.
It needs to be fairly reliably played.
The sound files are .flac, and I’m using default audio. The sound files are optimized, so is there a reason why it might be lagging? Should I use a library to help smooth it out? It does set the audio playback rate each time before it plays, is that affecting it?

Any advice is welcome, thank you!

More info:
I am using the Audio objects, and it’s all on the client side.
I’m pretty sure the audio is loading before the app starts, but I may have to look into making sure it does?

How much of a delay are we talking here? Absolutely make sure the audio is loaded on the client before you try to play it, as even a small network delay will be noticable.

I’d also suggest making sure the audio elements are all rendered on the page as well. How are you currently playing the sound?

A good resource is the web audio API documentation

Thanks for the input.
Yes it’s actually a couple times at random, but it is an app that plays .flac files in sequence so timing is extremely important, and any delay is indeed audible.
It does lag a bit more in the beginning if I try to play the sounds quickly after loading, so I should definitely look into that.

I just have it create sound via
x = new Audio(‘x.flac’)
and then call x.play() in a function when it’s needed.
I think it’s using the Web Audio API in this case.

One thing I should note is I use Audio.playbackspeed() function, but I don’t think that’s really the issue necessarily, just throwing it out there.

1 Like

You might require a decoder for Flac files. I remember in “the old internet” you couldn’t even play those because of the high lossless compression. This might help: Flac.js - JavaScripting

Can that help increase the efficiency of it?
I already can play .flac files, but I don’t have a decoder necessarily, the Audio API just supports it.

Also the more I examine it, the more I realize that the meteor timers might be a contributing problem; I think I have too many going at once and that might be throwing it off.

Hi…I’m here to say I have a similar issue:

At the point when I press play the cursor moves as though the sound is playing- - however for a short part of a second no sound is playing. This is irritating in light of the fact that you can’t put the cursor on a position and press play and hear sound from that spot. I need to ‘back up’ a piece and afterward press play to ensure I hear the sound I need.

In the event that I press play again from a similar position, I can hear the sound from the beginning position.