AudioSource.Play lags.

I’m working on an Android app where audio needs to be played when the user touches the screen. The problem is that there is a slight delay between the touch and the actual audio starting even though play is called in the same frame that the touch is registered. the delay seems to be anywhere from 2-7 frames worth and it’s not a consistent delay. I’ve tried changing the DSP buffer size down to 512x2 which is the lowest I can go without distorting the audio. Also using decompressed audio files doesn’t seem to help. there are a lot of audio files so keeping them compressed is ideal.

Has anyone else had this issue and what workarounds or fixes could be implemented?

:edit: I have tested other non unity android apps on the same device that have less lag.

Audio lag on Android is a known issue, and one that varies in severity from device to device (see here for an article from Google I/O presentation on the subject, and if you search here on UA you’ll find several posts on the topic).

MP3s certainly always feature a decompression lag, so you’ll want to keep your clips as uncompressed WAV. Are you playing the audio using PlayOneShot? That’s also inefficient - you should probably have a pool of instantiated AudioSources and just load in the appropriate clip.

You already mention you’ve reduced the buffer size. Other than that, I’m not sure there is a concrete solution :frowning:

I fixed music lag issue by swtiching this setting:
Player Settings → Project Settings → Audio → DSP Buffer Size → choose Best Performance. When I selected “best latency”, lag becomes even worst. (My device is Redmi 7A on Miui 11 Global). Leave other Audio settings as is (reset to default)


I also selected “decompress on load” + “preload audio data” for bg music files.