Skip to main content

Import audio

Overview

The process of importing audio at runtime can be broken down into several steps:

  1. Create a Runtime Audio Importer
  2. Bind to the needed delegates (OnProgress and OnResult)
  3. Import audio from a file or buffer
  4. Play the imported sound wave obtained from the OnResult delegate (more info is here)
Important Note

Ensure that both Runtime Audio Importer and Sound Wave instances are not prematurely garbage collected by maintaining a hard reference to them, which can be done by assigning them to separate variables using UPROPERTY(), TStrongObjectPtr, or any other method that prevents the object from being destroyed.

Supported Audio Formats

Runtime Audio Importer supports importing the following audio formats:

FormatDescription
MP3MPEG-1/2/2.5 Audio Layer I/II/III
WAVWaveform Audio File Format
FLACFree Lossless Audio Codec
OGG VORBISOgg container with Vorbis audio
OGG OPUSOgg container with Opus audio
BINKBink Audio
RAW (PCM)Uncompressed Pulse-Code Modulation audio data (Int8, UInt8, Int16, UInt16, Int32, UInt32, Float32)
tip

When importing audio, you can either specify the format explicitly or use automatic format detection based on file extension or content.

Streaming Audio Imports

For streaming scenarios where audio data is received incrementally (e.g., from a server, real-time capture, or network streams), consider using Streaming Sound Waves.

This method provides a continuous way to append audio data to the same sound wave's buffer, making it suitable for live streams or large files processed in chunks. See the Streaming Sound Wave documentation for more details.

Basic Implementation Steps

1. Create Runtime Audio Importer

First, you need to create a Runtime Audio Importer object. You should ensure it is treated as a strong reference by the garbage collector.

Create Runtime Audio Importer node

2. Bind to OnProgress Delegate

To track the progress of importing audio data, you can bind to the OnProgress (Blueprints) / OnProgressNative (C++) delegate.

An example of binding to the On Progress delegate

tip

This will allow you to monitor the progress and, for example, implement a loading screen.

3. Bind to OnResult Delegate

To be notified when the audio data import process is complete and to access the reference of the resulting sound wave, you must bind to the OnResult (Blueprints) / OnResultNative (C++) delegate.

An example of binding to the On Result delegate

warning

Make sure the imported sound wave is treated as a strong reference by the garbage collector to prevent unwanted premature garbage collection. This can be done by placing it as a separate variable in Blueprints.

4. Start Audio Import

Begin the audio import process by calling the relevant function, which can handle both compressed and uncompressed audio data formats.

Import Audio nodes examples

Utility Functions

Finding Audio Files

You can scan a directory for supported audio files:

Scan Directory For Audio Files node

Complete Example

Here's a full implementation example for importing audio:

Full example