Hi olaysia, Thanks so much for your help, this works like a charm! Recently, I've been working with custom lip sync data instead of input through a microphone, so I decided to repurpose this script to get the lip sync working. I was able to get the lip sync action occurring, but it doesn't quite match up with the words and it loops one more time before stopping even though the loop feature is disabled. I think it has to do with the last line, because I don't know what the equivalent to setting the timeSamples variable would be in my script.
using Meta.WitAi.TTS.Utilities;
using UnityEngine;
public class RuntimeAudioClipUpdater : MonoBehaviour
{
AudioSource audioSource;
[SerializeField] TTSSpeaker speaker;
private void Start()
{
audioSource = GetComponent<AudioSource>();
}
void Update()
{
if (audioSource != null)
{
AudioClip clip = audioSource.clip;
AudioClip referenceClip = null;
if (speaker.SpeakingClip != null)
{
referenceClip = speaker.SpeakingClip.clip;
}
if (clip != null && referenceClip != null)
{
int referenceClipId = referenceClip.GetInstanceID();
int currentClipId = clip.GetInstanceID();
if (currentClipId != referenceClipId)
{
//audioSource.Stop();
audioSource.clip = referenceClip;
audioSource.Play();
}
}
else if(referenceClip != null)
{
//audioSource.Stop();
audioSource.clip = referenceClip;
audioSource.Play();
}
}
//audioSource.timeSamples = speaker.AudioSource.timeSamples;
}
}
Here's what my script looks like right now. As you can see, I tried to set the audioSource timeSamples to be equal to the reference clip timeSamples that I'm sending in, but that's just redundant and doesn't work. Have you tried this type of thing before or have any insights on how to solve this problem?