Skip to content

API Reference parrot.clients.google.reel.music

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

parrot.clients.google.reel.music

View source

Music policy, isolated Lyria session and verified PCM->WAV encoding (FEAT-564, spec module M5).

Applies VideoReelRequest.music_policy/audio_mode, runs its OWN connect/receive loop against an isolated, owned SDK client (never generate_music_stream's shared stream — this service needs each chunk's mime_type to verify the PCM sample rate instead of guessing it), bounds connection/receive time and bytes, joins the receiver task on cancellation, and writes a verified-metadata WAV file.

Evidence gate (spec §8 Q6, "Lyria API version and PCM metadata are unverified"): see this task's Completion Note for the full resolution — summary: the sample RATE is read from each AudioChunk.mime_type at runtime (a real wire field, verified via SDK source inspection) rather than hardcoded from either of the two conflicting public sources (F011: repo docs say 48kHz, Google's public guide's player example uses 44.1kHz). Channel count (stereo) and sample width (16-bit) are NOT wire-verified — they are documented conventions, flagged distinctly from the wire-verified rate.

Alias GoogleGenAIClient

Re-exported from parrot.clients.google.client.GoogleGenAIClient.

Class MusicOutcome

Structured outcome of one music-generation attempt.

Fields:

Field Type Default Description
status Literal['off', 'succeeded', 'unavailable', 'timeout', 'failed', 'skipped']
local_path Optional[Path] None
warning Optional[str] None

Alias ReelError

Re-exported from parrot.clients.google.reel.errors.ReelError.

Alias ReelErrorCode

Re-exported from parrot.clients.google.reel.errors.ReelErrorCode.

Class ReelMusicService

Generates one background-music WAV for a reel, honoring music_policy.

Parameter Type Default Description
owner 'GoogleGenAIClient' The :class:GoogleGenAIClient that owns provider client lifecycle (get_client/close). This service builds and closes its OWN client, isolated from the director/video clients.
api_version str The API version this service's client is built with — configurable and tested, never the shared hardcoded default.
connect_timeout_seconds float _DEFAULT_CONNECT_TIMEOUT_SECONDS Bound on the initial connect handshake.
max_bytes int _DEFAULT_MAX_BYTES Bound on total received PCM bytes before aborting.

Method ReelMusicService.generate

Generates background music for a reel, per its audio_mode/music_policy.

audio_mode in {"native", "muted"} skips Lyria entirely (no connection). Otherwise: music_policy == "off" makes no connection either. "optional" (default) returns a structured failure outcome with a warning on any error. "required" raises a :class:ReelError on any error instead.

generate(request: VideoReelRequest, *, duration_seconds: float, output_directory: Path, deadline: float) -> MusicOutcome

Parameter Type Default Description
request VideoReelRequest The reel request (music_policy, audio_mode, music_prompt/music_genre/music_mood).
duration_seconds float The final assembled reel duration to target.
output_directory Path Directory the WAV file is written into.
deadline float Absolute time.monotonic()-comparable deadline.

Returns: MusicOutcome — class:MusicOutcome. Never None.

Raises:

  • ReelError — Only when music_policy == "required" and generation failed.
  • asyncio.CancelledError — Propagated unchanged.

Alias VideoReelRequest

Re-exported from parrot.models.google.VideoReelRequest.

Function write_pcm_wav

Writes raw PCM bytes to dest as a WAV file with exactly the given metadata.

Never used for speech (AbstractClient._save_audio_file keeps that role) — this is music's own writer so speech's mono/24kHz assumptions never leak into reel background music.

write_pcm_wav(pcm: bytes, dest: Path, sample_rate: int, channels: int, sample_width: int) -> Path

Parameter Type Default Description
pcm bytes Raw PCM audio bytes.
dest Path Destination path; a .wav suffix is enforced.
sample_rate int Sample rate in Hz — must be verified, never guessed.
channels int Number of audio channels.
sample_width int Bytes per sample (e.g. 2 for 16-bit PCM).

Returns: Path — dest with a .wav suffix.

Raises:

  • ValueError — Non-positive sample_rate/channels/sample_width.

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