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

# Audio Dispatch Module

[Overview](../overview) > Audio Dispatch Module

**Class:** `AudioDispatchModule` | **Inherits from:** `InworldAudioModule` | **Implements:** `ISendAudioHandler`

Audio dispatch module responsible for sending processed audio data to the Inworld service. Manages the transmission of audio samples and handles queuing, debugging, and test mode functionality. This module serves as the final stage in the audio processing pipeline before data reaches the server.

## Properties

* [ShortBufferToSend](#shortbuffertosend)
* [IsReadyToSend](#isreadytosend)
* [Samples](#samples)

## Methods

* [OnStartSendAudio](#onstartsendaudio)
* [OnStopSendAudio](#onstopsendaudio)

## Reference

### ShortBufferToSend

Gets the audio buffer to use for sending data to the Inworld service.
Returns either the processed buffer from an audio processor module or the raw input buffer.

#### Returns

**Type:** `CircularBuffer<float>`

***

### IsReadyToSend

Gets a value indicating whether the audio data is ready to be sent to the Inworld service.
Checks if the Inworld controller is available and properly initialized.

#### Returns

**Type:** `bool`

***

### Samples

Gets all the current audio samples ready for transmission.

#### Returns

**Type:** `List<float>`

***

### OnStartSendAudio

Called when the player starts being allowed to send audio into the buffer.
Implemented in the child class for custom behavior.

#### Returns

**Type:** `void`

***

### OnStopSendAudio

Called when the player stops being allowed to send audio into the buffer.
Automatically sends any remaining audio data and clears the queue.

#### Returns

**Type:** `void`

***

## Audio Dispatching Process

The AudioDispatchModule performs the following operations:

### Continuous Processing

* Runs a coroutine that executes every 0.1 seconds while the module is active
* Monitors the `Audio.IsPlayerSpeaking` state to determine when to process audio
* Converts buffer data to audio chunks when the player is speaking

### Buffer Management

* Uses `ShortBufferToSend` to determine the appropriate audio source
* Prioritizes processed audio buffer from `IProcessAudioHandler` if available
* Falls back to raw input buffer if no processor is present
* Tracks position to avoid processing the same data multiple times

### Audio Chunk Creation

* Converts audio samples to `AudioChunk` format with 16kHz sample rate
* Uses `InworldVector<float>` for data storage
* Queues audio data for transmission to the Inworld service

### Debug and Test Features

* **Audio Debugging**: When enabled, stores audio data in `m_DebugInput` for analysis
* **Test Mode**: Available for testing audio transmission without actual server communication

## Serialized Fields

The following fields are configurable in the Unity Inspector:

* **m\_IsAudioDebugging** (`bool`) - Enables audio debugging mode to store input data for analysis
* **m\_TestMode** (`bool`) - Enables test mode for audio transmission testing

## Important Notes

### Integration with Inworld Service

This module serves as the final stage in the audio processing pipeline, responsible for:

* Converting processed audio data into the format expected by the Inworld service
* Managing the transmission queue to ensure reliable data delivery
* Handling the transition between speaking and non-speaking states

### Buffer Priority

The module intelligently selects the audio source:

1. **Processed Buffer**: Uses `IProcessAudioHandler.ProcessedBuffer` if available
2. **Raw Buffer**: Falls back to `Audio.InputBuffer` if no processor is present

### Automatic Lifecycle Management

* **OnEnable**: Automatically starts the audio dispatching coroutine
* **OnDisable**: Stops the coroutine and cleans up resources
* **OnStopSendAudio**: Automatically sends remaining data and clears the queue

### Ready State Validation

The `IsReadyToSend` property validates that:

* InworldController instance exists
* STT module is available
* Audio queue contains data
* Module is properly initialized

***
