> ## Documentation Index
> Fetch the complete documentation index at: https://docs-unity.molca.id/llms.txt
> Use this file to discover all available pages before exploring further.

# AudioManager

> Music/SFX/voice playback with volume ducking, addressable clip loading, and mixer group routing.

**Namespace:** `Molca.Audio`\
**File:** `Packages/com.molca.core/Runtime/Audio/AudioManager.cs`\
**Type:** `RuntimeSubsystem` (child of [RuntimeManager](/core/runtime-manager) prefab)

## When to use

Use `AudioManager` to play music, SFX, and voice audio from [AudioLibrary](/core/audio-library) collections. It handles clip caching via Addressables, volume ducking during speech, and mixer group routing through the configured [AudioModule](/setup/global-settings).

## Role

* Manages three dedicated `AudioSource` channels: **music** (looping), **SFX** (one-shot), **voice** (with ducking).
* Loads audio clips from `AudioLibrary` collections through Addressables with ref-counted caching.
* Voice playback temporarily ducks music/SFX volume (duck amount and fade time configurable via Inspector).
* Volume control delegates to `AudioModule` on `GlobalSettings` and dispatches typed events on change.

## API Reference

### Playback controls

| Method           | Signature                                                                                                                     | Description                                                                   |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `PlayMusic`      | `async void PlayMusic(string collectionName, string id)`                                                                      | Play a looping music track from a collection. Crossfades from previous track. |
| `StopMusic`      | `void StopMusic()`                                                                                                            | Fade out and stop the current music track.                                    |
| `PlaySFX`        | `async void PlaySFX(string collectionName, string id, float volume = 1f, AudioSource audioSource = null)`                     | Play a one-shot SFX. Uses default SFX source or a custom AudioSource.         |
| `PlayVoice`      | `async void PlayVoice(string collectionName, string id, float volume = 1f, AudioSource audioSource = null)`                   | Play voice audio with ducking. Stops any current voice first.                 |
| `StopVoice`      | `void StopVoice()`                                                                                                            | Stop the current voice playback and restore ducked volumes.                   |
| `PlayFromSource` | `async void PlayFromSource(AudioSource source, string collection, string id, AudioLibrary.AudioType type, float volume = 1f)` | Play any audio type on a specified AudioSource.                               |

### Volume controls

| Method             | Signature                                                                | Description                                                                                   |
| ------------------ | ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------- |
| `SetMasterVolume`  | `void SetMasterVolume(float volume)`                                     | Set master volume (delegates to `AudioModule`, dispatches `TypedEvents.MasterVolumeChanged`). |
| `SetMusicVolume`   | `void SetMusicVolume(float volume)`                                      | Set music volume.                                                                             |
| `SetSFXVolume`     | `void SetSFXVolume(float volume)`                                        | Set SFX volume.                                                                               |
| `SetVoiceVolume`   | `void SetVoiceVolume(float volume)`                                      | Set voice volume.                                                                             |
| `SetupAudioSource` | `void SetupAudioSource(AudioSource source, AudioLibrary.AudioType type)` | Assign the correct mixer group to an AudioSource.                                             |

### Properties

| Property       | Type           | Description                                         |
| -------------- | -------------- | --------------------------------------------------- |
| `MusicLibrary` | `AudioLibrary` | Audio library for music clips (from `AudioModule`). |
| `SFXLibrary`   | `AudioLibrary` | Audio library for SFX clips.                        |
| `VoiceLibrary` | `AudioLibrary` | Audio library for voice clips.                      |
| `MasterVolume` | `float`        | Current master volume.                              |
| `MusicVolume`  | `float`        | Current music volume.                               |
| `SFXVolume`    | `float`        | Current SFX volume.                                 |
| `VoiceVolume`  | `float`        | Current voice volume.                               |

## Code

```csharp theme={null}
using Molca;
using Molca.Audio;
using UnityEngine;

public class UISounds : MonoBehaviour
{
    [Inject] private AudioManager _audio;

    private async void Start()
    {
        await RuntimeManager.WaitForInitialization();
    }

    public void OnButtonPress()
    {
        _audio.PlaySFX("UI", "click");
    }

    public void PlayBGM()
    {
        _audio.PlayMusic("Ambient", "main-theme");
    }
}
```

## Related

* [RuntimeManager](/core/runtime-manager) — `AudioManager` is a child subsystem
* [Global Settings](/setup/global-settings) — `AudioModule` configures mixer groups and libraries
* [EventDispatcher](/core/event-dispatcher) — dispatches `TypedEvents.MasterVolumeChanged` etc.
