Spaces:
Sleeping
Sleeping
| 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)}") | |