(audio: torch.Tensor, output_dir: Path, sample_rate: int)
| 298 | |
| 299 | |
| 300 | def save_batch_audio(audio: torch.Tensor, output_dir: Path, sample_rate: int) -> list[dict[str, Any]]: |
| 301 | output_dir.mkdir(parents=True, exist_ok=True) |
| 302 | stems: list[dict[str, Any]] = [] |
| 303 | for index in range(audio.shape[0]): |
| 304 | path = output_dir / ("audio.wav" if audio.shape[0] == 1 else f"audio_{index:02d}.wav") |
| 305 | torchaudio.save(str(path), audio[index].detach().cpu(), sample_rate, encoding="PCM_F") |
| 306 | stems.append({"name": f"audio_{index}", "audio": str(path), "summary": summarize_audio(path)}) |
| 307 | return stems |
| 308 | |
| 309 | |
| 310 | def run_request( |
no test coverage detected