(path: Path)
| 272 | |
| 273 | |
| 274 | def summarize_audio(path: Path) -> dict[str, Any]: |
| 275 | waveform, sample_rate = torchaudio.load(str(path)) |
| 276 | if waveform.numel() == 0: |
| 277 | raise RuntimeError("Stable Audio warmbench received empty audio") |
| 278 | audio = waveform.detach().cpu().numpy().astype(np.float64, copy=False) |
| 279 | channels = int(waveform.shape[0]) |
| 280 | frames = int(waveform.shape[1]) |
| 281 | return { |
| 282 | "sample_rate": int(sample_rate), |
| 283 | "channels": channels, |
| 284 | "samples": int(waveform.numel()), |
| 285 | "frames": frames, |
| 286 | "duration_sec": float(frames / sample_rate), |
| 287 | "sum": float(np.sum(audio, dtype=np.float64)), |
| 288 | "mean_abs": float(np.mean(np.abs(audio), dtype=np.float64)), |
| 289 | "rms": float(np.sqrt(np.mean(np.square(audio, dtype=np.float64)))), |
| 290 | "min": float(np.min(audio)), |
| 291 | "max": float(np.max(audio)), |
| 292 | } |
| 293 | |
| 294 | |
| 295 | def load_audio(path: Path) -> tuple[int, torch.Tensor]: |
no test coverage detected