Audio Validation
Audio file validation and inspection utilities.
This module provides functions to validate audio files and extract metadata like duration, sample rate, channel count, and format.
- class mixref.audio.validation.AudioInfo[source]
Bases:
NamedTupleAudio file information.
- duration
Duration in seconds
- Type:
- sample_rate
Sample rate in Hz
- Type:
- channels
Number of channels (1=mono, 2=stereo)
- Type:
- format
File format (e.g., ‘WAV’, ‘FLAC’, ‘MP3’)
- Type:
- subtype
Format subtype (e.g., ‘PCM_16’, ‘FLOAT’)
- Type:
- duration: float
Alias for field number 0
- sample_rate: int
Alias for field number 1
- channels: int
Alias for field number 2
- format: str
Alias for field number 3
- subtype: str
Alias for field number 4
- static __new__(_cls, duration, sample_rate, channels, format, subtype)
Create new instance of AudioInfo(duration, sample_rate, channels, format, subtype)
- mixref.audio.validation.get_audio_info(path)[source]
Get detailed information about an audio file.
- Parameters:
- Returns:
AudioInfo object with duration, sample rate, channels, format, and subtype
- Raises:
AudioFileNotFoundError – If the file doesn’t exist
CorruptFileError – If the file cannot be read or is corrupted
- Return type:
AudioInfo
Example
>>> info = get_audio_info("my_track.wav") >>> print(f"Duration: {info.duration:.2f}s at {info.sample_rate}Hz") Duration: 180.50s at 44100Hz
- mixref.audio.validation.validate_duration(path, min_duration=0.0, max_duration=None)[source]
Validate audio file duration is within acceptable range.
- Parameters:
- Returns:
Tuple of (is_valid, message). If valid, message is empty string.
- Raises:
AudioFileNotFoundError – If the file doesn’t exist
CorruptFileError – If the file cannot be read
- Return type:
Example
>>> is_valid, msg = validate_duration("track.wav", min_duration=30.0) >>> if not is_valid: ... print(f"Warning: {msg}")
- mixref.audio.validation.validate_sample_rate(path, expected_sr, tolerance=0)[source]
Validate audio file sample rate matches expected value.
- Parameters:
- Returns:
Tuple of (is_valid, message). If valid, message is empty string.
- Raises:
AudioFileNotFoundError – If the file doesn’t exist
CorruptFileError – If the file cannot be read
- Return type:
Example
>>> is_valid, msg = validate_sample_rate("track.wav", 44100) >>> if not is_valid: ... print(f"Sample rate mismatch: {msg}")