Search Unity

Question Connecting localized audio clips that contain numerical values

Discussion in 'Localization Tools' started by henn1ng, May 26, 2023.

  1. henn1ng

    henn1ng

    Joined:
    Apr 29, 2020
    Posts:
    3
    Hi!

    I would like to localize my game with the Unity Localization Tools and I'm wondering if there is a way to connect localized audio clips that include numerical values.

    My game is heavily dependent on voice audio so I need to localize spoken text like "1 out of 10 secrets found". For example, the German text would be "1 von 10 Geheimnisse gefunden".

    1 and 10 here are variables so essentially the string is something like "{global.current_secret} out of {global.num_secrets} secrets found". It would be awesome if I could use separate audio clips for the numerical values and for the connecting words.

    Is there a good way to implement this with the localization system? My guess is that I could set up localization rows for each of the parts and then connect them with my own script?

    I'm thankful for any help and advice!

    Best,
    Henning
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,288
    Hi,

    In theory, it could be possible to construct sentences from audio clips although I suspect it could get complicated and require a lot of audio clips that can fit together seamlessly.

    Its unlikely that you would have the same audio clips for each language so I would do a language-specific approach.
    Maybe create a ScriptableObject to build your sentences and then have each sentence builder asset stored in a Asset Table for the language.

    Something like this:

    Code (csharp):
    1. public class SentenceBuilder : ScriptableObject
    2. {
    3.     [Serializable]
    4.     class AudioClipSnippet
    5.     {
    6.         public AudioClip audioClip;
    7.         public string text;
    8.     }
    9.  
    10.     public List<AudioClipSnippet> audioClips;
    11.  
    12.     public void BuildSentence(string text)
    13.     {
    14.         // Go through the text looking for matching audio clips.
    15.         // If each snippet is a single word then you can do a split and check each, however
    16.         // if some snippets can be longer than a word then you will need a way to try and match the clips. Maybe a Trie could work here?
    17.     }
    18. }
    Alternatively, you could create a class to represent a specific sentence and then configure the audio clips for each part. You would likely need to create an instance for each language so you can handle the word order and structure changing.

    I think the key here is to have some sort of ScriptableObject asset that can be added to an Asset Table so you can get the version for the current language.
     
  3. henn1ng

    henn1ng

    Joined:
    Apr 29, 2020
    Posts:
    3
    Hi Karl!

    That's super helpful! I didn't even think about grouping the clips together like this and scriptable objects make total sense here. I will try and implement it like this.

    Thank you!
    Henning
     
    karl_jones likes this.