FormatParser.Audio (format_parser v2.14.0)

Copy Markdown

An Audio struct and functions.

The Audio struct contains the fields format, sample_rate_hz, num_audio_channels, intrinsics and nature.

Supported Formats

FormatSample RateChannelsIntrinsics
:aiffnum_frames, bits_per_sample
:wavbyte_rate, block_align, bits_per_sample
:vorbisvorbis_version
:opusversion, pre_skip, output_gain, mapping_family
:flac
:mp3
:aac
:midiformat, num_tracks, time_division

Summary

Types

t()

A struct representing a parsed audio file.

Functions

Parses an audio file or result.

Types

t()

@type t() :: %FormatParser.Audio{
  format: atom() | nil,
  intrinsics: map(),
  nature: :audio,
  num_audio_channels: integer() | nil,
  sample_rate_hz: integer() | nil
}

A struct representing a parsed audio file.

Fields

  • :format - The audio format as an atom (e.g., :wav, :mp3, :flac)
  • :sample_rate_hz - The sample rate in Hz (e.g., 44100, 48000), if available
  • :num_audio_channels - The number of audio channels (e.g., 1 for mono, 2 for stereo)
  • :nature - Always :audio for audio files
  • :intrinsics - A map containing format-specific metadata

Functions

parse(file)

@spec parse({:error, binary()} | binary() | any()) :: any()

Parses an audio file or result.

  • If given a tuple {:error, file} where file is a binary, attempts to parse the audio file.
  • If given a binary file, attempts to parse the audio file.
  • For any other input, returns the input as-is (passthrough for parser chain).

Examples

iex> {:ok, file} = File.read("priv/test.wav")
iex> result = FormatParser.Audio.parse(file)
iex> result.format
:wav
iex> result.sample_rate_hz
48000

iex> FormatParser.Audio.parse(%FormatParser.Image{})
%FormatParser.Image{}