# 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="/files/r2TUIwL185eQ9nFxx9Fv" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bizachi-dev.gitbook.io/languagesystem-pro/getting-started/publish-your-docs-5.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
