Reference

Contents

Index

AudioReader.loadMethod
load(filename::AbstractString; kwargs...) -> AudioFile

Load an audio file from disk with automatic format detection and optional processing.

This is the main entry point for loading audio files in AudioReader. It automatically detects the file format, validates the file content, loads the raw audio data, and optionally applies processing transformations.

Arguments

  • filename::AbstractString: Path to the audio file to load

Keyword Arguments

  • sr::Union{Nothing,Int64}=nothing: Target sample rate for resampling
    • nothing: Keep original sample rate
    • Int64: Resample to specified rate in Hz
  • norm::Bool=false: Whether to normalize audio amplitude to [-1, 1] range
  • mono::Bool=true : Whether to convert multi-channel audio to mono

Returns

  • AudioFile: Processed audio data with metadata

Supported Formats

  • Lossless: WAV, FLAC, OGG (via libsndfile)
  • Lossy: MP3 (via mpg123)

Examples

# Basic loading (keeps original properties)
audio = load("music.wav")

# Load and resample to 16kHz
audio = load("speech.wav"; sr=16000)

# Load, convert to mono, and normalize
audio = load("stereo_music.flac"; mono=true, norm=true)

# Full processing pipeline
audio = load("audio.mp3"; sr=22050, norm=true, mono=false)

# Access loaded data
data = data(audio)          # Get audio samples
sample_rate = samplerate(audio)     # Get current sample rate
orig_sr = orig_sr(audio)    # Get original sample rate of audiofile 
                              (identical to samplerate(audio) if no resample was applied)
channels = nchannels(audio) # Get number of channels
normalized = norm(audio)    # Return true if audio was normalized

See also: AudioFile

source
AudioReader.AudioFileType
AudioFile{T} <: AbstractAudioFile

Wrapper for processed audio data with metadata and type safety.

This struct represents audio data that has been loaded and potentially processed (resampled, normalized, converted to mono).

Type Parameters

  • T: Element type of the audio data (typically Float32 or Float64)

Fields

  • data::AudioFormat{T}: Stored audio data as Vector (mono) or Matrix (multi-channel)
  • sr::Int64: Current sample rate in Hz after any resampling
  • origin_sr::Int64: Original sample rate in Hz from the source file
  • norm::Bool: Whether the audio data has been normalized

See also: load

source
Missing docstring.

Missing docstring for origin_sn(audiofile::AudioFile). Check Documenter's build log for details.

AudioReader.FileType
File{F<:AbstractDataFormat} <: AbstractFormatted{F}

Type-safe representation of an audio file with format information.

This struct provides a type-parameterized container for audio files that encodes the file format in the type system. This enables compile-time format dispatch and ensures type safety when working with different audio formats.

Type Parameters

  • F<:AbstractDataFormat: The audio format type (e.g., AbstractDataFormat{:WAV})

Fields

  • filename::String: The canonical file path as a string

Arguments

  • file: File path as string or existing File object

Examples

# Explicit format specification
wav_file  = File{format"WAV"}("audio.wav")
mp3_file  = File{format"MP3"}("music.mp3")
flac_file = File{format"FLAC"}("high_quality.flac")

# Get file properties
filename(wav_file)       # Returns "path_to_audio.wav"
file_extension(wav_file) # Returns ".wav"
formatname(wav_file)     # Returns :WAV

# Type information is preserved
typeof(wav_file)         # File{AbstractDataFormat{:WAV}}

See also: @format_str

source
AudioReader.@format_strMacro
@format_str(s)

Create an AbstractDataFormat type for the given format string.

This macro provides a convenient string literal syntax for creating format types used in file I/O operations. It converts a string into the corresponding AbstractDataFormat{Symbol} type at compile time.

Arguments

  • s: Format string ("WAV", "MP3", "FLAC", "OGG")

Returns

  • AbstractDataFormat{Symbol}: Type representing the specified format

Examples

# Create format types using string literals
wav_format  = format"WAV"     # AbstractDataFormat{:WAV}
mp3_format  = format"MP3"     # AbstractDataFormat{:MP3}
flac_format = format"FLAC"   # AbstractDataFormat{:FLAC}

# Use in File construction
file = File{format"WAV"}("audio.wav")

See also: File, File, formatname

source
Missing docstring.

Missing docstring for formatname. Check Documenter's build log for details.