Skip to content

API Reference parrot_formdesigner.renderers.audio

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

parrot_formdesigner.renderers.audio

View source

AudioFormRenderer — Standalone audio form renderer for parrot-formdesigner.

Converts a FormSchema into an AudioFormManifest — a sequential list of questions suitable for a voice-driven Q&A session over WebSocket.

The renderer is registered under the "audio" format key and is discoverable at GET /api/v1/forms/{form_uid}/render/audio.

Added by FEAT-224 (FormDesigner Audio Renderer).

Alias AbstractFormRenderer

Re-exported from parrot_formdesigner.renderers.base.AbstractFormRenderer.

Alias AudioFormManifest

Re-exported from parrot_formdesigner.audio.models.AudioFormManifest.

Class AudioFormRenderer

Renders a FormSchema as an AudioFormManifest (sequential questions).

The manifest is returned as RenderedForm.content (a dict) with content_type="application/json". Optionally pre-synthesizes TTS audio for each question when a VoiceSynthesizer is provided.

The renderer is registered under the "audio" format key by _seed_default_renderers() in api/render.py.

Example::

renderer = AudioFormRenderer()
result = await renderer.render(form_schema, locale="en")
manifest = result.content  # dict with form_uid, questions, ws_endpoint, ...
Parameter Type Default Description
synthesizer Optional['VoiceSynthesizer'] None Optional VoiceSynthesizer. When provided, each question will have its label synthesized to bytes stored in AudioQuestion.audio_prompt.

Method AudioFormRenderer.split_into_questions

Flatten a FormSchema into a sequential list of AudioQuestion objects.

Iterates all sections → subsections → fields. Skips HIDDEN and ARRAY fields. Expands GROUP fields by flattening their children into individual questions.

Each question carries its section/subsection context (GROUP children inherit the parent's). required is the static field.required; the dynamic value is applied by the planner from RuleResolution.required.

split_into_questions(form: FormSchema, *, locale: str = 'en') -> list[AudioQuestion]

Parameter Type Default Description
form FormSchema The FormSchema to convert.
locale str 'en' BCP 47 locale for label resolution.

Returns: list[AudioQuestion] — Ordered list of AudioQuestion objects, one per voiced field.

Method AudioFormRenderer.render

Render a FormSchema into an AudioFormManifest.

Flattens the form into a sequential question list. Optionally pre-synthesizes TTS audio for each question using the injected VoiceSynthesizer.

render(form: FormSchema, style: StyleSchema | None = None, *, locale: str = 'en', prefilled: dict[str, Any] | None = None, errors: dict[str, str] | None = None) -> RenderedForm

Parameter Type Default Description
form FormSchema The form to render.
style StyleSchema | None None Ignored for the audio renderer.
locale str 'en' BCP 47 locale for label resolution.
prefilled dict[str, Any] | None None Ignored for the audio renderer.
errors dict[str, str] | None None Ignored for the audio renderer.

Returns: RenderedForm — RenderedForm with content as a dict (AudioFormManifest.model_dump()) and content_type="application/json".

Alias AudioQuestion

Re-exported from parrot_formdesigner.audio.models.AudioQuestion.

Alias AudioSessionConfig

Re-exported from parrot_formdesigner.audio.models.AudioSessionConfig.

Alias FieldType

Re-exported from parrot_formdesigner.core.types.FieldType.

Alias FormField

Re-exported from parrot_formdesigner.core.schema.FormField.

Alias FormSchema

Re-exported from parrot_formdesigner.core.schema.FormSchema.

Alias FormSubsection

Re-exported from parrot_formdesigner.core.schema.FormSubsection.

Alias LocalizedString

Re-exported from parrot_formdesigner.core.types.LocalizedString.

Alias RenderedForm

Re-exported from parrot_formdesigner.core.schema.RenderedForm.

Alias StyleSchema

Re-exported from parrot_formdesigner.core.style.StyleSchema.

Alias VoiceMode

Re-exported from parrot_formdesigner.audio.models.VoiceMode.

Function build_audio_synthesizer

Build a VoiceSynthesizer preferring SuperTonic, else None (FEAT-236).

Constructs a VoiceSynthesizer configured with the preferred TTS backend (config.tts_backend, default "supertonic"). The backend itself is created lazily on first synthesize() — no model is loaded here. Returns None when the parrot.voice TTS stack is not importable at all (text-only session). The SuperTonic→Google→text-only fallback at synthesis time lives in :func:synthesize_with_fallback.

build_audio_synthesizer(config: AudioSessionConfig | None = None) -> 'VoiceSynthesizer | None'

Parameter Type Default Description
config AudioSessionConfig | None None Optional session config carrying tts_backend, tts_voice and tts_mime_format.

Returns: 'VoiceSynthesizer | None' — A configured VoiceSynthesizer, or None if voice TTS is unavailable.

Function classify_voice_mode

Classify a FormField into a VoiceMode (FEAT-236).

A per-field override in field.meta["voice_mode"] (case-insensitive match against the VoiceMode values) wins over the default FieldType table. An invalid override logs a warning and falls back to the default.

classify_voice_mode(field: FormField) -> VoiceMode

Parameter Type Default Description
field FormField The FormField to classify.

Returns: VoiceMode — The VoiceMode for this field.

Alias field_voice_meta

Re-exported from parrot_formdesigner.core.voice.field_voice_meta.

Alias is_sensitive

Re-exported from parrot_formdesigner.core.voice.is_sensitive.

Alias llm_validation_enabled

Re-exported from parrot_formdesigner.core.llm_validation.llm_validation_enabled.

Attribute logger

Alias render_author_prompt

Re-exported from parrot_formdesigner.audio.narration.engine.render_author_prompt.

Function synthesize_with_fallback

Synthesize text to audio bytes, SuperTonic→Google→text-only.

The single reusable place for the FEAT-236 graceful-degradation contract (shared by the renderer and the WebSocket handler). Tries the preferred backend first (default SuperTonic), then Google. Any ImportError/ValueError/RuntimeError raised by a backend (missing extra, unconfigured weights, no inference_fn) is caught and the next backend is tried. Returns None when no backend is usable — the caller delivers the question text-only. NEVER raises for a missing/misconfigured backend (FEAT-231 contract).

synthesize_with_fallback(text: str, *, config: AudioSessionConfig | None = None, language: str | None = None) -> bytes | None

Parameter Type Default Description
text str The text to synthesize.
config AudioSessionConfig | None None Optional session config (preferred backend, voice, mime).
language str | None None Optional BCP 47 language hint for the backend.

Returns: bytes | None — Raw audio bytes, or None for a text-only fallback.

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