Audio
Interface for the discord-luau Audio package: audio sources and a paced player for a voice connection. Runs on Zune
only, because voice and opus load native libraries through FFI, and audio files decode through
discord_luau/symphonia, which does too.
A file source holds a native decoder session from the moment it is built. A source not handed to a playAsync that
starts must be released with source:destroy().
Summary
Properties
Audio.player :: Audio.PlayerAudio.fromOpus :: (packets: { buffer } | () -> buffer?) -> SourceAudio.fromPCM :: (pcm: buffer | { buffer } | () -> buffer?, options: PCMOptions?) -> SourceAudio.fromFile :: (path: string, options: FileOptions?) -> SourceAudio.fromEncoded :: (bytes: buffer | string, options: FileOptions?) -> SourceAudio.fromMP3 :: (bytes: buffer | string, options: NamedOptions?) -> SourceAudio.fromOgg :: (bytes: buffer | string, options: NamedOptions?) -> SourceAudio.fromWAV :: (bytes: buffer | string, options: NamedOptions?) -> SourceAudio.fromFLAC :: (bytes: buffer | string, options: NamedOptions?) -> SourceAudio.fromAAC :: (bytes: buffer | string, options: NamedOptions?) -> SourceAudio.fromM4A :: (bytes: buffer | string, options: NamedOptions?) -> SourceAudio.fromWebM :: (bytes: buffer | string, options: NamedOptions?) -> SourceAudio.fromMKV :: (bytes: buffer | string, options: NamedOptions?) -> SourceAudio.fromAIFF :: (bytes: buffer | string, options: NamedOptions?) -> SourceAudio.fromCAF :: (bytes: buffer | string, options: NamedOptions?) -> SourceAudio.fromStream :: (read: StreamReader, options: StreamOptions?) -> SourceAudio.fromProcess :: (command: string, arguments: { string }?, options: StreamOptions?) -> SourceFunctions
Audio.loadFileDecoder()Properties
Section titled “Properties”player
Section titled “player”audio.player.new(connection, options?) builds a player for a voice connection. See Audio.Player.
fromOpus
Section titled “fromOpus”Builds a source from Opus packets. See Audio.Source.
fromPCM
Section titled “fromPCM”Builds a source from 48 kHz stereo 16-bit little-endian PCM of any length; options.bitrate sets the Opus bitrate
(128000 by default). See Audio.Source.
fromFile
Section titled “fromFile”Builds a source from the audio file at path, streamed from the disk. See Audio.Source.
fromEncoded
Section titled “fromEncoded”Builds a source from an audio file held in memory; the format is found from the content. See Audio.Source.
fromMP3
Section titled “fromMP3”fromEncoded for an MP3, MP2 or MP1 file. Any supported file plays through it. See Audio.Source.
fromOgg
Section titled “fromOgg”fromEncoded for an Ogg file: Vorbis, FLAC, or Opus passed through. Any supported file plays through it. See
Audio.Source.
fromWAV
Section titled “fromWAV”fromEncoded for a WAV file: PCM or ADPCM. Any supported file plays through it. See Audio.Source.
fromFLAC
Section titled “fromFLAC”fromEncoded for a FLAC file. Any supported file plays through it. See Audio.Source.
fromAAC
Section titled “fromAAC”fromEncoded for an ADTS AAC file: AAC-LC, mono or stereo. Any supported file plays through it. See
Audio.Source.
fromM4A
Section titled “fromM4A”fromEncoded for an M4A or MP4 file: AAC-LC in mono or stereo, ALAC, or Opus passed through. Any supported file
plays through it. See Audio.Source.
fromWebM
Section titled “fromWebM”fromEncoded for a WebM file: Opus passed through, or Vorbis. Any supported file plays through it. See
Audio.Source.
fromMKV
Section titled “fromMKV”fromEncoded for a Matroska file. Any supported file plays through it. See Audio.Source.
fromAIFF
Section titled “fromAIFF”fromEncoded for an AIFF file. Any supported file plays through it. See Audio.Source.
fromCAF
Section titled “fromCAF”fromEncoded for a Core Audio Format file. Any supported file plays through it. See Audio.Source.
fromStream
Section titled “fromStream”Builds a source from an audio file that arrives in pieces: read returns the next chunk of its bytes and nil at
the end, and may yield. Nothing is read or opened until the source plays; the player waits while it buffers
options.bufferSeconds of audio (1 by default) and whenever it stalls. See Audio.Source.
fromProcess
Section titled “fromProcess”Builds a stream source from what a program writes to its stdout, such as
audio.fromProcess("yt-dlp", { "-f", "251", "-o", "-", url }). The program starts when the source plays; a
non-zero exit code fails the playback with the program's last stderr line. See Audio.Source.
Functions
Section titled “Functions”loadFileDecoder
Section titled “loadFileDecoder”Audio . loadFileDecoder ( ) -> ()
Loads libsymphonia, the library the file sources decode with, so the first file source neither waits for it nor yields. The load always yields; when the library is not cached it downloads the 2 to 3 MB file, and it checks the library's sha256, which blocks the VM for about 360 ms. Call it once at startup, from a thread that can yield. Later calls return at once.
Raises Symphonia requires FFI which is not available on this runtime without FFI, and any error the load hits; a
failed load is not cached, so the next call or file source tries again.