Home

Awesome

com.utilities.audio

Discord openupm openupm

A simple package for audio extensions and utilities in the Unity Game Engine.

Installing

Requires Unity 2021.3 LTS or higher.

The recommended installation method is though the unity package manager and OpenUPM.

Via Unity Package Manager and OpenUPM

Via Unity Package Manager and Git url

Documentation

On its own this package doesn't do too much but provide base functionality for recording audio in the Unity Editor and during runtime. Instead, use the encoder packages to fully utilize this package and its contents.

Table of Contents

Encoder Packages

Recording Manager

This class is meant to be used anywhere you want to be able to record audio. You can use one of the encoder packages to be able to record and encode to the specific format other than PCM.

A perfect example implementation on how to use the RecordingManager is in the AbstractRecordingBehaviour<TEncoder> class.

Start Recording while streaming to disk

var (savedPath, recordedClip) = await RecordingManager.StartRecordingAsync<PCMEncoder>("my recording", "directory/to/save");

Start Recording and callback each sample

using var stream = new MemoryStream();
await RecordingManager.StartRecordingStreamAsync<PCMEncoder>(sample => stream.Write(sample, 0, sample.Length));

Recording Behaviour

A basic PCMRecordingBehaviour is included in this package to enable basic recording to any project. Simply add this component to any GameObject in your scene. This class inherits from AbstractRecordingBehaviour<TEncoder>.

AbstractRecordingBehaviour<TEncoder> is really meant to be a good baseline example of how to use the RecordingManager. This abstract class is implemented in each of the encoder packages for simplicity and ease of use. You can use this class as an example of how to implement your own recording behaviours.

Audio Clip Extensions

Provides extensions to encode AudioClips to PCM encoded bytes. Supports 8, 16, 24, and 32 bit sample sizes.

Encode PCM

// Encodes the audioClip to raw PCM bytes.
var pcmBytes = audioClip.EncodeToPCM();

Decode PCM

// Decodes the raw PCM byte data and sets it to the audioClip.
audioClip.DecodeFromPCM(pcmBytes);

IEncoder

This package also includes an IEncoder interface to allow for custom encoders to be implemented. This interface is used in the encoder packages to allow for custom encoders to be implemented.

The interface contains the following methods: