Spaces:
Sleeping
Sleeping
File size: 831 Bytes
87601f5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import soundfile as sf
import librosa
import numpy as np
def read_audio_info(path):
"""Read audio file metadata using soundfile.info"""
info = sf.info(path)
return {
"samplerate": int(info.samplerate),
"channels": int(info.channels),
"frames": int(info.frames),
"subtype": info.subtype,
"format": info.format,
"duration": float(info.frames) / info.samplerate if info.frames else 0.0
}
def load_audio_mono(path):
"""
Always load safely as mono using Librosa.
This helper keeps the original logic untouched.
"""
try:
y, sr = librosa.load(path, sr=None, mono=True)
if np.isnan(y).any():
y = np.nan_to_num(y)
return y, sr
except Exception as e:
raise RuntimeError(f"Audio loading failed: {str(e)}")
|