Repository navigation
Contract Polly TTS
This page mirrors specs/001-max-height-ai-character/contracts/polly-tts.md. Polly is the primary voice path for completed agent turns from Contract-Message-Protocol, with browser speech as the budget-degraded fallback.
| Parameter | Value |
|---|---|
Engine |
neural |
VoiceId |
Matthew |
LanguageCode |
en-US |
Audio OutputFormat
|
mp3 |
Audio SampleRate
|
24000 |
Viseme OutputFormat
|
json |
SpeechMarkTypes |
['viseme'] |
TextType |
ssml |
SSML wrapper:
<speak><prosody rate="105%">{response_text}</prosody></speak>The contract source notes that Polly neural voices do not support pitch on <prosody>. Raised pitch and nasal tone are client-side DSP concerns, not SSML.
IAM correction (2026-11-07). The frozen spec 001 contract's
polly:Engine/polly:VoiceId conditions are unsupported by AWS. The voice
configuration above is enforced by request construction, not IAM. Grant
polly:SynthesizeSpeech on * with aws:RequestedRegion = us-west-2.
Source-Amazon-Polly records the service authorization reference; spec 003's
active execution-role contract has been corrected without editing spec 001.
interface PollyAudioRequest {
Engine: 'neural';
VoiceId: 'Matthew';
LanguageCode: 'en-US';
OutputFormat: 'mp3';
SampleRate: '24000';
TextType: 'ssml';
Text: string;
}
interface PollyVisemeRequest {
Engine: 'neural';
VoiceId: 'Matthew';
LanguageCode: 'en-US';
OutputFormat: 'json';
SpeechMarkTypes: ['viseme'];
TextType: 'ssml';
Text: string;
}
interface VisemeMark {
time: number;
type: 'viseme';
value: string;
}
interface TtsResult {
audioData: Uint8Array | null;
visemeMarks: VisemeMark[] | null;
textOnly: boolean;
}Viseme response is newline-delimited JSON, one object per mark:
{"time":0,"type":"viseme","value":"p"}
{"time":50,"type":"viseme","value":"E"}- Receive
agent_turn_complete.fullText. - Truncate text to 2,900 chars as a safety margin.
- Wrap in SSML.
- Run audio synthesis and viseme synthesis in
Promise.all. - Decode MP3 through
AudioContext. - Route through the audio chain for pitch shift, stutter loop, static burst, EQ, volume, and analyser-driven mouth animation.
- Store viseme marks for future 3D lip-sync; MVP binary mouth animation ignores them.
| Case | Required behavior |
|---|---|
| Polly throttle | Retry audio once after 500 ms. |
| Second audio failure | Fall back to text-only unless browser TTS is active. |
| Viseme failure | Ignore for MVP; log/retain debuggability for V1. |
| Text too long | Truncate before synth; responses should already be bounded by FR-009. |
| $8 soft-degrade | Disable Polly; use browser SpeechSynthesis if available, else text-only. |
| $10 hard-stop | Disable interaction via budget state. |
Browser fallback voice selection priority is high-quality en-US voice, then any en-US, then any en, then system default. Browser fallback uses pitch = 1.2 and rate = 1.05; these are not the same units as the AudioWorklet pitch ratio.
The Promise.all in step 4 is two billable requests, not one. AWS bills Speech
Marks per character at the same rate as speech, so every reply costs twice
its character count — see Source-Amazon-Polly and the corrected estimate
on Decision-Polly-Voice.
Step 7 is also the project's only tie to a Polly-specific feature. Viseme speech marks are how Polly exposes phoneme timing; the MVP's analyser-driven binary mouth does not need them, but the V1 3D lip-sync this contract stores them for does. Any future change of TTS provider has to answer where visemes come from, which is why Source-Nova-Sonic treats it as a migration cost rather than a detail.
packages/frontend/src/services/pollyTts.ts implements dual SynthesizeSpeechCommand calls, the exact Polly constants above, SSML rate wrapping, 2,900-character truncation, 429 retry, text-only fallback, and viseme parsing. budgetDegradation.ts switches between normal, browser_tts, text_only, and hard_stop, with an in-character first fallback message. See Contract-Greeting-Manifest for pre-generated greeting audio, which avoids runtime Polly calls during startup.
- Concept-Cloud-Only-Inference
- Concept-Budget-Ceiling
- Concept-Personality-Gate
- Concept-IP-And-Legal-Posture
- Concept-Supply-Chain-Discipline
- Concept-Graceful-Degradation
- Concept-Observability
- Concept-Testing-And-TDD
- Concept-Credential-Hygiene
Editing in the browser? Wiki edits are live and bypass wiki:lint. Read
Guide-Wiki-Contributing first.