class

Discord::DCAParser

Inherits Reference / Object

Parser for the DCA file format, a simple wrapper around Opus made specifically for Discord bots.

Constants

DCA1_MAGIC = "DCA1"

Magic string that identifies a DCA1 file

Constructors

new(io : IO, raw = false, strict_metadata : Bool = true)

Create a new parser. It will read from the given io. If raw is set, the file is assumed to be a DCA0 file, without any metadata. If the file's metadata doesn't conform to the DCA1 specification and strict_metadata is set, then the parsing will fail with an error; if it is not set then the metadata will silently be nil.

Source

Instance methods

metadata

The parsed metadata, or nil if it could not be parsed.

Source
next_frame(reuse_buffer = false) : Bytes | Nil

Reads the next frame from the IO. If there is nothing left to read, it will return nil.

If reuse_buffer is true, a large buffer will be allocated once and reused for future calls of this method, reducing the load on the GC and potentially reusing memory use overall; if it is false, a new buffer of just the correct size will be allocated every time. Note that if the buffer is reused, the returned data is only valid until the next call to next_frame.

Source
parse

Continually reads frames from the IO until there are none left. Each frame is passed to the given block.

Source