> ## 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.

# Inworld Audio Buffer

[Overview](./overview) > Inworld Audio Buffer

**Class:** `UInworldAudioBuffer` | **Inherits from:** `UObject`

Audio buffer for collecting and managing voice recording data. This class provides functionality for buffering audio chunks during voice recording, allowing for efficient collection and processing of audio data before sending it for further processing. It manages sample rate consistency, data accumulation, and provides thread-safe operations for audio data handling.

Key features:

* Thread-safe audio data collection

* Sample rate validation and consistency checking

* Minimum duration enforcement before flushing

* Event-driven architecture with flush notifications

## Methods

* [Add](#add)
* [CreateAudioBuffer](#createaudiobuffer)
* [Flush](#flush)

## Reference

### Add

Adds an audio chunk to the audio buffer.
This function appends the provided audio data to the buffer.
Ensures that the incoming audio chunk matches the buffer's sample rate and channel configuration.
If the chunk is incompatible, the function will abort.

<img src="https://mintcdn.com/inworldai/StlB2j_TRDiuzJEK/img/unreal/runtime/nd_img_Add.png?fit=max&auto=format&n=StlB2j_TRDiuzJEK&q=85&s=3f5751b272c3302af54ebb4bc2cdeed7" alt="Add Blueprint Node" width="226" height="138" data-path="img/unreal/runtime/nd_img_Add.png" />

## Examples

```c++ theme={"system"}
void Add(const FInworldData_Audio& AudioChunk)
```

#### Parameters

| Parameter  | Type                        | Description                                                                            |
| ---------- | --------------------------- | -------------------------------------------------------------------------------------- |
| AudioChunk | `const FInworldData_Audio&` | The audio data to add to the buffer. Must match the buffer's sample rate and channels. |

***

### CreateAudioBuffer

Creates a new audio buffer to record voice.
This function initializes an instance of UInworldAudioBuffer using the provided configuration.
It allows customization of the sample rate and channels.

<img src="https://mintcdn.com/inworldai/mZNEEtl7pbzQ55cC/img/unreal/runtime/nd_img_CreateAudioBuffer.png?fit=max&auto=format&n=mZNEEtl7pbzQ55cC&q=85&s=0dab524eaebbaabad7746337a27fc705" alt="CreateAudioBuffer Blueprint Node" width="202" height="92" data-path="img/unreal/runtime/nd_img_CreateAudioBuffer.png" />

## Examples

```c++ theme={"system"}
UInworldAudioBuffer* CreateAudioBuffer(const FInworldAudioBufferConfig& Config)
```

#### Parameters

| Parameter | Type                               | Description                                                   |
| --------- | ---------------------------------- | ------------------------------------------------------------- |
| Config    | `const FInworldAudioBufferConfig&` | The configuration struct containing sample rate and channels. |

#### Returns

**Type:** `UInworldAudioBuffer*`
**Description:** A pointer to the newly created UInworldAudioBuffer instance.

***

### Flush

Flushes the collected audio data from the buffer. If the buffer contains audio data, it constructs an FInworldData\_Audio and broadcasts it via the OnAudioBufferFlush delegate. After broadcasting, the buffer is cleared. If the buffer is empty, this function does nothing. Events: OnAudioBufferFlush

<img src="https://mintcdn.com/inworldai/mZNEEtl7pbzQ55cC/img/unreal/runtime/nd_img_Flush.png?fit=max&auto=format&n=mZNEEtl7pbzQ55cC&q=85&s=7bbdc8364930ba222ab456b4b0b0d9c7" alt="Flush Blueprint Node" width="226" height="108" data-path="img/unreal/runtime/nd_img_Flush.png" />

## Examples

```c++ theme={"system"}
FInworldData_Audio Flush()
```

#### Returns

**Type:** `FInworldData_Audio`

***
