Skip to main content

Streaming Sound Wave

For Voice Activity Detection (VAD), refer to this page.

A streaming sound wave is a type of imported sound wave that supports adding audio data dynamically, even during playback. It offers the same functionality as an imported sound wave, e.g. rewinding, and can be used in SoundCues, etc.

Creating a streaming sound wave

First you should create a streaming sound wave. Please note that you should treat it as a strong reference to prevent premature destruction (e.g. by assigning it to a separate variable in Blueprints or using UPROPERTY() in C++).

Create Streaming Sound Wave node

Playing the sound wave

You can then play back that sound wave. However, this is not necessary to do now, you can start playing the sound wave later.

Various examples of playing a sound wave

Pre-allocating audio data

Optionally, you can pre-allocate audio data (bytes) to avoid reallocating the entire PCM buffer each time new audio data is appended.

Pre Allocate Audio Data node

Appending audio data

To add audio data to the end of the existing buffer, use the appropriate functions for dynamically appending audio data. The playback will follow the queue sequence of these appends.

Append Audio Data node

Avoiding accelerated or distorted audio playback

When streaming audio data while the sound wave is playing, you may experience accelerated or distorted audio playback in specific scenarios. This issue typically occurs when:

  1. The sound wave playback is near/at the end of the current buffer
  2. New audio data is being continuously queued into the streaming sound wave
  3. The playback catches up to the incoming data stream

You can stop populating audio data at any time without issues. However, for scenarios where you need continuous streaming (such as real-time audio streaming), there are two approaches depending on your audio data streaming reliability:

For reliable, consistent streaming: Use the OnPopulateAudioState delegate to start playback immediately after the first chunk is received.

For unreliable streaming (network issues, intermittent data): Add an additional delay even after OnPopulateAudioState is triggered to build up a larger buffer before starting playback.

Using OnPopulateAudioState to avoid playback issues

Note: You can stop populating audio data at any time without causing playback issues. The exact approach depends on your audio data streaming reliability - use immediate playback for consistent streams, or add additional buffering delay for unreliable streams (e.g., network connectivity issues).

Example usage

Finally, your implementation might look like this:

An example of using a streaming sound wave

On Populate Audio State

The OnPopulateAudioState delegate functions similarly to OnPopulateAudioData but doesn't broadcast the populated audio data. This can be useful when you want to track when the audio data is populated without passing an array of the populated audio data, which can improve performance.

On Populate Audio State delegate

Working with PCM Data

For real-time access to PCM data during playback, see PCM Data Handling.