| 61 | |
| 62 | |
| 63 | def write_wav(path: Path, sample_rate: int, audio: np.ndarray) -> None: |
| 64 | path.parent.mkdir(parents=True, exist_ok=True) |
| 65 | audio = np.asarray(audio, dtype=np.float32).reshape(-1) |
| 66 | audio = np.clip(audio, -1.0, 1.0) |
| 67 | pcm = (audio * 32767.0).astype(np.int16) |
| 68 | with wave.open(str(path), "wb") as handle: |
| 69 | handle.setnchannels(1) |
| 70 | handle.setsampwidth(2) |
| 71 | handle.setframerate(sample_rate) |
| 72 | handle.writeframes(pcm.tobytes()) |
| 73 | |
| 74 | |
| 75 | def summary_json(audio: np.ndarray, sample_rate: int, wall_ms: float) -> str: |