Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Audio Sound is played with a delay.

Discussion in 'Audio & Video' started by dhanrajsinh24, Jul 22, 2018.

  1. dhanrajsinh24

    dhanrajsinh24

    Joined:
    May 8, 2014
    Posts:
    56
    I have used "Best Latency" in the sound manager and still the sound has a very big delay while playing. Is there a solution for this?
     
  2. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    1,164
    Is it an audio sample, like an mp3 or wav etc?
     
  3. dhanrajsinh24

    dhanrajsinh24

    Joined:
    May 8, 2014
    Posts:
    56
    @BrandyStarbrite I have tried several audio files(.mp3, .ogg, .wav) but doesn't make any difference, same delay in every format. I am just using AudioSource.PlayOneShot(audio clip, nothing else. Is it Unity bug? I'm using latest Unity(2018) by the way.
     
  4. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    1,164
    Okay, thanks for that info.
    Oh crap! I forgot to ask this question:

    Is the delay, at the start of each audio clip?

    And, when you play the audio clips, in an external media player
    like vlc media player etc, is there a delay?
     
    Last edited: Jul 29, 2018
  5. dhanrajsinh24

    dhanrajsinh24

    Joined:
    May 8, 2014
    Posts:
    56
    BrandyStarbrite likes this.
  6. thegodofbass

    thegodofbass

    Joined:
    Apr 22, 2018
    Posts:
    1
    Has anyone had any progress on this?

    I get latency in Windows just running this test scene in the editor - not on android or anything - this is all the scene is, a single object with this code which plays a snare .wav file:

    Code (CSharp):
    1. public class playSound : MonoBehaviour {
    2.  
    3.     public AudioClip prefabSound;
    4.     AudioSource audioSource;
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.         audioSource = GetComponent<AudioSource>();
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update () {
    13.         if (Input.GetKeyDown("space")){
    14.             audioSource.PlayOneShot(prefabSound, 1F);
    15.         }
    16.     }
    17. }
    1. Latency is set to "best"
    2. Sounds are "decompress on load" and "preload audio data"
    3. The .wav files do not have any baked delay in them, they start at 0.
    4. If I get the getkeydown to do something visual there is no visual delay, so I don't think it's input delay.
     
  7. joshwaloveslotr

    joshwaloveslotr

    Joined:
    Jul 11, 2018
    Posts:
    1
    Did you ever solve this problem?
     
  8. bkdroid13

    bkdroid13

    Joined:
    Jun 3, 2019
    Posts:
    8
    I am facing this problem. please let me know your opinion.
     
  9. dormouse

    dormouse

    Joined:
    Mar 1, 2011
    Posts:
    65
    we are facing the same issue....nobody has a solution on that yet ?
     
  10. Benergy

    Benergy

    Joined:
    Jun 18, 2019
    Posts:
    9
    My guess would be that PlayOneShot() creates this delay because the sound has to be loaded into memory first. Is there still a delay if you set the clip of the audio source in the editor and just call Play() in the script?
     
  11. danilvolfson

    danilvolfson

    Joined:
    Aug 16, 2018
    Posts:
    2
    That's happen with Play() too.
     
  12. Wilma258

    Wilma258

    Joined:
    Jun 26, 2019
    Posts:
    1
    Facing the same problem, please help me.
     
  13. Benergy

    Benergy

    Joined:
    Jun 18, 2019
    Posts:
    9
    Does this delay correlate with the loading state of the clip? Perhaps try something like:

    Code (CSharp):
    1. public class ExampleClass : MonoBehaviour
    2. {
    3.     public AudioClip clip;
    4.  
    5.     void Start()
    6.     {
    7.         AudioSource audioSource = GetComponent<AudioSource>();
    8.         audioSource.PlayOneShot(clip);
    9.  
    10.         do {
    11.             Debug.Log(clip.loadState);
    12.         } while (clip.loadState != AudioDateLoadState.Loaded)
    13.     }
    14. }
    or something like this (perhaps set the Debug.Log() line in the Update method). Check the console and see if the time until it's loaded roughly equals the delay.

    Also, how long is the delay? Are we talking of like 50ms, 500ms, 1sec or even longer?
     
    Last edited: Jun 27, 2019
  14. Bosskee

    Bosskee

    Joined:
    Sep 17, 2019
    Posts:
    1
    A general tip to everyone who's experiencing this issue is to ensure that you're not testing over bluetooth audio.
     
    jbpelletier likes this.