Reference
Contents
Index
AudioReader.AudioFile
AudioReader.File
AudioReader.data
AudioReader.data
AudioReader.file_extension
AudioReader.filename
AudioReader.is_norm
AudioReader.load
AudioReader.nchannels
AudioReader.samplerate
AudioReader.@format_str
AudioReader.load
— Methodload(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 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 normalized
See also: AudioFile
AudioReader.AudioFile
— TypeAudioFile{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 (typicallyFloat32
orFloat64
)
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
See also: load
AudioReader.data
— Methoddata(file)
Returns the audio data associated with File
file
.
AudioReader.samplerate
— Methodsamplerate(file)
Returns the sample rate associated with File
file
.
AudioReader.nchannels
— Methodnchannels(file::AudioFile) -> Int
Return the number of audio channels in an AudioFile.
Missing docstring for origin_sn(audiofile::AudioFile)
. Check Documenter's build log for details.
AudioReader.is_norm
— Methodis_norm(file::AudioFile) -> Bool
Check whether the audio file data has been normalized.
AudioReader.File
— TypeFile{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
— Methodfilename(file)
Returns the filename associated with File
file
.
AudioReader.data
— Methoddata(file)
Returns the audio data associated with File
file
.
AudioReader.file_extension
— Methodfile_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