Search Unity

Audio Audio delay while using OVRLipSync

Discussion in 'Audio & Video' started by movish, May 29, 2023.

  1. movish

    movish

    Joined:
    May 18, 2023
    Posts:
    1
    I am using OVRLipSync for lip syncing of my reallusion avatar. I have attached audio source to the component of my avatar and added an audio clip for the same. OVRLipSync generates visemes from audio clip coming from audio source, I have mapped them to the corresponding morph targets for visemes of the avatar. But whenever I play the game, the audio starts playing early and the script takes some time to load (there's a popup also showing Waiting for Unity's code to finish executing). I want the audio to play after the code finishes executing.
     
  2. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    421
    You could start you AudioClip on a delegate triggered when you script is done.

    Code (CSharp):
    1. // AudioTrigger.cs
    2. [RequireComponent(typeof(AudioSource))]
    3. public class AudioTrigger : MonoBehaviour
    4. {
    5.     // Create a delegate type for the audio trigger.
    6.     public delegate void AudioTriggerDelegate();
    7.  
    8.     // Instantiate a public delegate of the AudioTriggerDelegate type.
    9.     public AudioTriggerDelegate audioTriggerDelegate;
    10.  
    11.     void Start()
    12.     {
    13.         // Make the delegate point to the PlayAudio method.
    14.         audioTriggerDelegate = PlayAudio;
    15.     }
    16.  
    17.     private void PlayAudio()
    18.     {
    19.         // Get the AudioSource from the same GameObject and play it.
    20.         GetComponent<AudioSource>().Play();
    21.     }
    22. }
    23.  
    24. // SomeOtherScript.cs
    25. public class SomeOtherScript : MonoBehaviour
    26. {
    27.     // Assume that an AudioTrigger is set on the same GameObject.
    28.     AudioTrigger audioTrigger;
    29.  
    30.     void YourCode()
    31.     {
    32.         //...
    33.         audioTrigger.audioTriggerDelegate?.Invoke();
    34.     }
    35. }
    36.  

    EDIT: Well... now that I wrote that I think the delegate is overkill and you could probably simply trigger the sound directly when you detect that your loading script is finished..