# 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 `audioID`s 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.

```csharp
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.

```csharp
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`.

```csharp
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`.

```csharp
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**.

```csharp
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.

<figure><img src="https://3626215024-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF9jo80etwnAiJ4U7LlGC%2Fuploads%2FhFbTEYPze8YmiIRyjWce%2FAudioManager.png?alt=media&#x26;token=52293098-f1b4-4c08-b261-a6c4d5a941b5" alt=""><figcaption></figcaption></figure>
