baml.media.Audio

An audio clip value.

Reference version

Signature

class baml.media.Audio

An audio clip value.

Backed by a URL or by base64-encoded content. A file is read when the value is built from it: the value holds its content, never its path.

Source:<builtin>/baml/ns_media/media.bamlbytes 2983–5653

Fields

_data

$rust_type

Static methods

function

from_base64

(base64: string, mime_type: string | null) -> audio throws never

Creates an Audio value from a base64-encoded string. Optionally specify mime_type.

function

from_file

(
file: string,
mime_type: string | null

Creates an Audio value from the content of a local file, which is read now. The value is named by the file's base name. Optionally specify mime_type; otherwise it is inferred from the file's name.

Throws

  • Io if the file cannot be opened or read.
  • InvalidArgument only as baml.fs.open declares it: a path that cannot be opened is Io.
function

from_file_content

(file: string, base64: string, mime_type: string | null) -> audio throws never

Creates an Audio value from base64-encoded content that was read from file. The value is named by the file's base name. Optionally specify mime_type; otherwise it is inferred from the file's name.

function

from_url

(url: string, mime_type: string | null) -> audio throws never

Creates an Audio value from a URL. Optionally specify mime_type.

function

infer_mime_type

(source: string) -> string throws never

Returns the MIME type that source, a file name or URL, implies for an audio clip: by its extension, or the usual type for an audio clip when the extension says nothing. A URL's query and fragment are not part of its extension.

Instance methods

function

base64

(self) -> string throws never

Returns the base64-encoded content of this audio clip.

function

mime_type

(self) -> string | null throws never

Returns the MIME type of this audio clip, or null if not set.

function

name

(self) -> string | null throws never

Returns the name of this audio clip, or null if it has none. An audio clip built from a file is named by the file's base name.

function

url

(self) -> string | null throws never

Returns the URL of this audio clip, or null if it was not constructed from a URL.

Implementations

baml.Concrete for T

Source:<builtin>/baml/core.bamlbytes 763–795