scripts/pcm_to_wav.py

agentic-awesome-skills · skills/podcast-generation/scripts/pcm_to_wav.py · python · MIT
voice, tag:knn-classified

Converts raw PCM audio to WAV format and calculates duration.

#!/usr/bin/env python3
# Source: https://github.com/sickn33/agentic-awesome-skills | License: MIT | Copyright 2026 Antigravity User
# Provided via justclaw.it.com; keep this notice with the code.
"""Convert raw PCM audio data to WAV format.

Azure OpenAI Realtime API outputs PCM audio (24kHz, 16-bit, mono).
This script converts it to standard WAV format for browser playback.

Usage:
    from pcm_to_wav import pcm_to_wav
    wav_bytes = pcm_to_wav(pcm_data, sample_rate=24000)
"""

import struct
import io


def pcm_to_wav(
    pcm_data: bytes,
    sample_rate: int = 24000,
    channels: int = 1,
    sample_width: int = 2
) -> bytes:
    """Convert raw PCM audio data to WAV format.

    Args:
        pcm_data: Raw PCM audio bytes
        sample_rate: Samples per second (default 24000 for gpt-

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key