audio.play_pcm

Wrap raw PCM bytes as a waveform and play them from memory.

Syntax

ue.audio.play_pcm(pcm_bytes: string, options: table) -> number?, error?

Options

FieldTypeDescription
sample_rateinteger?Samples per second, 8,000–192,000. Defaults to 44,100.
channelsinteger?1 for mono or 2 for stereo. Defaults to 1.
bits_per_sampleinteger?8 or 16. Defaults to 16.

Returns

Returns the duration in seconds after playback begins, or nil, error.

Example

local seconds = assert(ue.audio.play_pcm(response.body, {
    sample_rate = 44100,
    channels = 1,
    bits_per_sample = 16
}))

The provider's PCM format must exactly match these options. Fish Audio PCM is 16-bit mono; use the same sample rate requested from its API.

Notes

The runtime constructs a PCM RIFF/WAVE header around the supplied bytes. Raw audio is limited to 16 MiB. Playback is asynchronous, non-spatial, and replaces any currently playing Lua sound.

On this page