voicechat.play Asynchronous

Start loading an audio file from the workspace, or one the user picks with openfiledialog, and mix its playback into the current voice capture path. The call returns while decoding continues, so inspect getstatus for progress or an error.

Syntax
Luau
voicechat.play(source: string | Document, avoid_convert: boolean?) -> ()

Parameters

Function parameters
ParameterTypeDescription
sourcestring | DocumentWorkspace-relative audio file path, or a file Document returned by openfiledialog.
avoid_convertboolean?Optional boolean. True copies matching decoded PCM16 samples directly into the outgoing frame.

Returns

()

No values.

Usage notes

A path must be a nonempty workspace-relative string. A Document must be a file rather than a folder, and it does not need shared-storage access.

The direct path requires PCM16 audio at the outgoing submittedrate and submittedchannels with speed 1. Otherwise playback uses normal conversion. Roblox still encodes the outgoing voice.

For 48000 Hz mono, run ffmpeg -i input.mp3 -ar 48000 -ac 1 -c:a pcm_s16le output.wav in a shell, then put output.wav in the workspace audio folder. Set -ar and -ac to match the submittedrate and submittedchannels reported by getstatus.

Explicit nil in the second slot is rejected. Voice capture must be available in an active game session.

Limits

ResourceLimitWhat happens
Source file512 MiBA larger file sets the error state in voicechat.getstatus.
Decoded PCM512 MiBDecoding stops and sets the error state in voicechat.getstatus. Use a shorter file.
Decoded format8–384 kHz with 1–8 channelsA file outside these bounds sets the error state in voicechat.getstatus.

play returns before decoding finishes, so these failures do not raise. Check state and error in voicechat.getstatus after starting a clip.

Example

Example
Luau
local path = "audio/intro.mp3" -- Or let the user pick a file below.
local source = isfile(path) and path or openfiledialog({ title = "Choose audio" })
if source and voicechat.getstatus().available then
    voicechat.setspeed(1)
    voicechat.play(source, true)
    print("Loading:", voicechat.getstatus().state)
end