How to feed localizedAudioClip Into an Audioclip type Array

Hi
I want to feed a list of localized asset (audioclip), into an different array. But it dosent seem to wants to get fed into the new array named TTSLocal[ ].
If i debug the Result i see that it has the right KeyID and is the type of AudioClip. With no errors im stumped on what is going wrong.

public LocalizedAudioClip[] localAudioMessages;
public AudioClip[] TTSLocal;

   private void Start()
    {
TTSLocal = new AudioClip[localAudioMessages.Length];
     }
    
public void GetAudioMessages()
    {
        for (int i = 0; i < localAudioMessages.Length; i++)
        {
            StartCoroutine(GetAudioMessage(i));
        }
    }

public IEnumerator GetAudioMessage(int i)
    {
        var localeAudioMessage = LocalizationSettings.AssetDatabase.GetLocalizedAssetAsync<AudioClip>(TableName, localAudioMessages[i].TableEntryReference.KeyId);
        while (!localeAudioMessage.IsDone)
        {
            yield return null;
        }
        TTSLocal[i] = localeAudioMessage.Result;

We got the same functionality for localizedStrings working.

 public LocalizedString[] localizedMessages;
 public string[] messages;

   private void Start()
    {
 messages = new string[localizedMessages.Length];
     }
    public void GetTextMessages()
    {
        for (int i = 0; i < localizedMessages.Length; i++)
        {
            StartCoroutine(GetTextMessage(i));
        }
    }
var localeMessage = LocalizationSettings.StringDatabase.GetLocalizedStringAsync(StringTableName, localizedMessages[i].TableEntryReference.KeyId);
        while (!localeMessage.IsDone)
        {
            yield return null;
        }
        messages[i] = localeMessage.Result;

Are you getting any errors?
Is localeAudioMessage.Result null?
Why do you use a different table from the LocalizedAudioClip?
Can you do localAudioMessages.GetAssetAsync() instead?
This should do the table and Key Id for you

I would not do this localAudioMessages[i].TableEntryReference.KeyId
If the EntryReference is a name it would fail. The safest thing to do would be to use localAudioMessages[i].TableEntryReference. This will use KeyId for you unless the value is using a Name.

using the table reference didn’t work. we used keyID because before with the string array, it only worked when we added it

localeAudioMessage.Result is null as you can see from the Debug.Log below

we get this error, not sure if it is related

We want to save the AudioClips in an array so we can load them at start and use it at will with the scripts without loading them

Thank you for the help

Are you able to share the project so I can take a look?

1 Like