Skip to content

API Reference parrot_tools.google.audio_utils

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.google.audio_utils

View source

Audio utilities for Google Lyria PCM streaming and WAV framing.

Attribute BYTES_PER_SECOND

Attribute DEFAULT_CHANNELS

Attribute DEFAULT_SAMPLE_RATE

Attribute DEFAULT_SAMPLE_WIDTH

Function async_save_pcm_to_wav

Non-blocking async wrapper around :func:save_pcm_to_wav.

async_save_pcm_to_wav(pcm_bytes: bytes, output_path: Union[str, Path], sample_rate: int = DEFAULT_SAMPLE_RATE, channels: int = DEFAULT_CHANNELS, sample_width: int = DEFAULT_SAMPLE_WIDTH) -> Path

Parameter Type Default Description
pcm_bytes bytes Raw PCM audio bytes.
output_path Union[str, Path] Target file path (will ensure .wav extension).
sample_rate int DEFAULT_SAMPLE_RATE Sample rate in Hz (default 48000).
channels int DEFAULT_CHANNELS Number of channels (default 2 for stereo).
sample_width int DEFAULT_SAMPLE_WIDTH Bytes per sample (default 2 for 16-bit).

Returns: Path — Resolved Path to written WAV file.

Function async_slice_wav_file

Non-blocking async wrapper around :func:slice_wav_file.

async_slice_wav_file(input_wav: Union[str, Path], output_wav: Union[str, Path], target_seconds: float) -> Path

Parameter Type Default Description
input_wav Union[str, Path] Path to source WAV file.
output_wav Union[str, Path] Destination path for truncated WAV.
target_seconds float Desired duration in seconds.

Returns: Path — Resolved Path to truncated output WAV file.

Function pcm_bytes_to_seconds

Calculate audio duration in seconds from raw PCM byte count.

pcm_bytes_to_seconds(byte_count: int, sample_rate: int = DEFAULT_SAMPLE_RATE, channels: int = DEFAULT_CHANNELS, sample_width: int = DEFAULT_SAMPLE_WIDTH) -> float

Parameter Type Default Description
byte_count int Number of raw PCM bytes.
sample_rate int DEFAULT_SAMPLE_RATE Audio sampling frequency in Hz (default: 48000).
channels int DEFAULT_CHANNELS Channel count (default: 2 for stereo).
sample_width int DEFAULT_SAMPLE_WIDTH Bytes per sample per channel (default: 2 for 16-bit).

Returns: float — Duration in seconds represented by the given byte count.

Function save_pcm_to_wav

Package raw PCM bytes into a valid RIFF/WAVE file on disk.

save_pcm_to_wav(pcm_bytes: bytes, output_path: Union[str, Path], sample_rate: int = DEFAULT_SAMPLE_RATE, channels: int = DEFAULT_CHANNELS, sample_width: int = DEFAULT_SAMPLE_WIDTH) -> Path

Parameter Type Default Description
pcm_bytes bytes Raw PCM audio bytes.
output_path Union[str, Path] Target file path (will ensure .wav extension).
sample_rate int DEFAULT_SAMPLE_RATE Sample rate in Hz (default 48000).
channels int DEFAULT_CHANNELS Number of channels (default 2 for stereo).
sample_width int DEFAULT_SAMPLE_WIDTH Bytes per sample (default 2 for 16-bit).

Returns: Path — Resolved Path to written WAV file.

Function seconds_to_pcm_bytes

Calculate required PCM bytes for a given duration in seconds.

seconds_to_pcm_bytes(seconds: float, sample_rate: int = DEFAULT_SAMPLE_RATE, channels: int = DEFAULT_CHANNELS, sample_width: int = DEFAULT_SAMPLE_WIDTH) -> int

Parameter Type Default Description
seconds float Target duration in seconds.
sample_rate int DEFAULT_SAMPLE_RATE Audio sampling frequency in Hz (default: 48000).
channels int DEFAULT_CHANNELS Channel count (default: 2 for stereo).
sample_width int DEFAULT_SAMPLE_WIDTH Bytes per sample per channel (default: 2 for 16-bit).

Returns: int — Total bytes representing the duration.

Function slice_wav_file

Truncate an existing WAV file to exactly target_seconds.

slice_wav_file(input_wav: Union[str, Path], output_wav: Union[str, Path], target_seconds: float) -> Path

Parameter Type Default Description
input_wav Union[str, Path] Path to source WAV file.
output_wav Union[str, Path] Destination path for truncated WAV.
target_seconds float Desired duration in seconds.

Returns: Path — Resolved Path to truncated output WAV file.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally