LanguageSystem Pro
  • Welcome
  • Getting Started
    • Quickstart
    • Importing and Exporting
    • InternalDatabase Mode
    • ExternalFiles Mode
    • GlobalExternal Mode
    • ComponentBased Mode
    • Importing Translated Text into Custom Script
    • LanguageAudioManager
    • AudioWarper Component
    • Importing Audio into Custom Script
    • Switching Languages
    • LanguageManagerEditor
Powered by GitBook
On this page
  1. Getting Started

LanguageAudioManager

LanguageAudioManager

Overview

The LanguageAudioManager is a singleton class in the LanguageSystem PRO that manages language-specific audio clips. It allows you to easily manage and retrieve audio files based on the current language setting in your game. You can use it to play localized audio, such as voiceovers or sound effects, which change depending on the selected language.

Key Features

  • Audio by Language: Automatically plays the correct audio file based on the game's current language.

  • Audio Identification: Each audio clip is assigned an audioID for easy reference.

  • Language-Specific Audio Management: The system allows you to manage multiple audio clips for each language and audioID.

  • Audio Format Flexibility: Works with standard Unity AudioClip objects, meaning you can use any supported audio format (e.g., MP3, WAV, etc.).

How It Works

The LanguageAudioManager stores audio clips using an audioID that maps to multiple language-specific AudioClip objects. When the audio is requested, it automatically selects the clip associated with the current language and returns or plays it.

Example Setup

  • Add the LanguageAudioManager component to a GameObject in your scene (e.g., an empty GameObject or an audio manager GameObject).

  • In the Inspector, configure the audioEntries list to include audioIDs and associated language-specific audio clips.

AudioEntry and LanguageAudio Structure

Each AudioEntry consists of:

  • audioID: A string identifier for the audio (e.g., "greeting", "gameOver").

  • languageAudios: A list of LanguageAudio objects, where each entry links a language ID (e.g., "en", "pt-BR") to its corresponding AudioClip.

API Reference

GetAudioByID(string audioID)

Returns the AudioClip for the given audioID in the current language.

AudioClip clip = LanguageAudioManager.Instance.GetAudioByID("greeting");
  • Parameters:

    • audioID: The ID of the audio file (e.g., "greeting").

  • Returns:

    • The AudioClip for the specified audioID and the current language, or null if not found.

AudioExists(string audioID)

Checks if a specific audio clip exists for the given audioID in the current language.

bool exists = LanguageAudioManager.Instance.AudioExists("greeting");
  • Parameters:

    • audioID: The ID of the audio to check.

  • Returns:

    • true if the audio exists, otherwise false.

PlayAudioByID(string audioID, AudioSource audioSource)

Plays the audio clip associated with the given audioID on the provided AudioSource.

LanguageAudioManager.Instance.PlayAudioByID("gameOver", audioSource);
  • Parameters:

    • audioID: The ID of the audio to play.

    • audioSource: The AudioSource where the audio will be played.

GetAvailableLanguagesForAudio(string audioID)

Returns a list of all available languages for the given audioID.

List<string> languages = LanguageAudioManager.Instance.GetAvailableLanguagesForAudio("greeting");
  • Parameters:

    • audioID: The ID of the audio for which to retrieve available languages.

  • Returns:

    • A List<string> of language IDs that have associated audio clips.

Example: Play Localized Audio

Here's an example of how you can play localized audio using the LanguageAudioManager.

public class PlayLocalizedAudio : MonoBehaviour
{
    public string audioID; // Unique audio ID for this sound
    public AudioSource audioSource; // AudioSource component

    private void Start()
    {
        LanguageAudioManager.Instance.PlayAudioByID(audioID, audioSource);
    }
}

Integrating with Custom Scripts

To integrate LanguageAudioManager into your custom scripts, use the audioID to retrieve and play audio clips based on the current language, as shown in the example above.

PreviousImporting Translated Text into Custom ScriptNextAudioWarper Component

Last updated 8 months ago