"""Shared helpers for google-gemini-media examples."""
import wave
from pathlib import Path

def save_wav(path: str, pcm: bytes, rate: int = 24000, channels: int = 1, sample_width: int = 2) -> None:
    """Save PCM16LE mono audio bytes as a WAV file."""
    out = Path(path)
    out.parent.mkdir(parents=True, exist_ok=True)
    with wave.open(str(out), "wb") as wf:
        wf.setnchannels(channels)
        wf.setsampwidth(sample_width)
        wf.setframerate(rate)
        wf.writeframes(pcm)
