Reference
Contents
Index
AudioReader.AudioFileAudioReader.FileAudioReader.file_extensionAudioReader.filenameAudioReader.get_dataAudioReader.get_nchannelsAudioReader.get_origin_srAudioReader.get_srAudioReader.is_normAudioReader.loadAudioReader.@format_str
AudioReader.load — Method
load(filename::AbstractString; kwargs...) -> AudioFileLoad 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 resamplingnothing: Keep original sample rateInt64: Resample to specified rate in Hz
norm::Bool=false: Whether to normalize audio amplitude to [-1, 1] rangemono::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 normalizedSee also: AudioFile
AudioReader.AudioFile — Type
AudioFile{T} <: AbstractAudioFileWrapper 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 (typicallyFloat32orFloat64)
Fields
data::AudioFormat{T}: Stored audio data as Vector (mono) or Matrix (multi-channel)sr::Int64: Current sample rate in Hz after any resamplingorigin_sr::Int64: Original sample rate in Hz from the source filenorm::Bool: Whether the audio data has been normalized
Constructor
AudioFile(file::SampleBuf; sr=nothing, norm=false, mono=true, format=Float32)file: Source audio buffer.sr: Target sample rate (optional; if not given, uses original).norm: If true, normalizes audio data.mono: If true, converts audio to mono.format: Output data type (default:Float32).
The constructor loads and processes audio data, applying type conversion, mono conversion, resampling, and normalization as requested.
See also: load
AudioReader.get_data — Method
get_data(file::AudioFile) -> ArrayReturns the audio data associated with AudioFile file.
AudioReader.get_sr — Method
get_sr(file::AudioFile) -> Int64Returns the sample rate associated with AudioFile file.
AudioReader.get_origin_sr — Method
origin_sr(file::AudioFile) -> Int64Return the original sample rate of the AudioFile file before any resampling. Return the same value of sr() if any reasmplig was applied.
AudioReader.get_nchannels — Method
get_nchannels(file::AudioFile) -> Int64Return the number of audio channels in an AudioFile file.
AudioReader.is_norm — Method
is_norm(file::AudioFile) -> BoolCheck whether the AudioFile file data has been normalized.
AudioReader.File — Type
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
AudioReader.filename — Method
filename(file)Returns the filename associated with File file.
AudioReader.file_extension — Method
file_extension(file)Returns the file extension associated with File file.
AudioReader.@format_str — Macro
@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