# Speech simulation (no TTS)

Goal: sound that is *heard as someone speaking* — with rhythm, melody, pauses, emotion, identity — without
words that need to be understood. Uses: game dialogue "voices", creatures and robots, background chatter,
radio/PA texture, placeholder VO timing, UI personality.

## The techniques (and which engine covers them)

| Technique | Idea | Known from | Here |
|---|---|---|---|
| Formant (source–filter) synthesis | glottal pulse train through moving vowel resonances + noise for consonants | Klatt 1980, DECtalk, SAM | `engine: 'formant'` |
| Articulatory / waveguide tract | a tube whose shape changes like a mouth (Kelly–Lochbaum) | Pink Trombone, vocal-tract models | `engine: 'tract'` |
| Per-letter grains | one short pitched sound per character | Animal Crossing "Animalese", Undertale / visual-novel blips | `engine: 'blip'` |
| Prosody-only murmur | melody and rhythm of speech with articulation blurred | "adults" in Peanuts, speech through walls, Simlish-like babble | `engine: 'mumble'` |
| Scrambled phonemes | real syllable structure, re-labelled sounds | invented languages | `voice.gibberish` 0–1 (any engine) |
| Crowd walla | many independent murmurs | film background loops | `crowd()` |
| Treatments | band-limit, ring-mod, pitch/formant scaling, reverb | radio, robots, giants, ghosts | `voiceFx()` + voice `size`/`pitch` |
| Concatenated syllable samples | recorded nonsense syllables re-ordered | Banjo-Kazooie, Okami | not built in: `granulate`/slice a recording, schedule by `planSpeech` units |

## Using it

```js
const { buf, duration, marks } = sd.speak('Привет, странник! Куда ты идёшь так поздно?', {
  engine: 'formant',                      // 'formant' | 'tract' | 'blip' | 'mumble'
  voice: { pitch: 110, size: 1.0, range: 1, rate: 5, breath: 0.1, rough: 0, tension: 0.5 },   // or a VOICES key
  seed: 3 });
// marks: [{ word, t }] — word onsets for lip-flap, subtitles, text reveal sync
```
Text does the directing: punctuation becomes prosody. `.` falls and pauses; `?` rises on the last syllable;
`!` starts higher, louder, with bigger accents; `,` lifts slightly and pauses briefly; `…` trails; ALL CAPS is
louder and higher; word and syllable counts set the rhythm. Latin and Cyrillic are mapped to phoneme classes;
other scripts are hashed consistently into classes, so any text produces deterministic babble.

Voice parameters (all engines unless noted):

| Parameter | Effect | Range / examples |
|---|---|---|
| `pitch` Hz | base f0 | giant 60 · man 110 · woman 200 · child 300 · imp 380+ |
| `size` | vocal-tract length factor: formants scale by 1/size | child 0.75 · woman 0.86 · man 1 · giant 1.35. Pitch and size are independent: high pitch + big size = strange creature |
| `range` | depth of intonation | 0.1 monotone/robot · 1 neutral · 1.8 excited/cartoon |
| `rate` syll/s | tempo | 3 slow/old · 5 neutral · 7+ hurried |
| `breath` 0–1 | aspiration noise in the voice | 0.05 pressed · 0.3 breathy · with `whisper: 1` fully unvoiced |
| `rough` 0–1 | jitter, shimmer, occasional fry | age, monsters, strain |
| `tension` 0–1 | source brightness (lax ↔ pressed) | calm 0.3 · shouted 0.8 |
| `vibrato`, `tremor` | 5.5 Hz / 7 Hz pitch wobble | singers / frailty, fear |
| `articulation` 0–1 | how far vowels/consonants move from neutral | 1 crisp · 0.5 lazy · 0.2 mumble |
| `gibberish` 0–1 | share of phonemes re-labelled | 0 follows the text's sounds · 1 invented language with the text's rhythm |
| blip: `wave`, `spread`, `legato` | square/triangle/sine/saw/chirp/bubble; per-letter pitch spread (st); grain length | character identity for blip voices |

`VOICES` (man, woman, child, elder, giant, imp, whisper, monotone) are starting points; a character is usually
one of them with two or three values pushed.

## Making characters

Identity comes from a few stable choices plus a treatment:

- **Body** = `pitch` + `size`. Keep both fixed per character; never randomize them between lines.
- **Temperament** = `range`, `rate`, `tension`: nervous (wide, fast, tense), stoic (narrow, slow), sly (slow with
  wide range), tired (falling, breathy, low tension).
- **Texture** = `breath`, `rough`, and `voiceFx(buf, kind)`: `radio`, `phone`, `pa`, `robot`, `demon`, `ghost`,
  `alien`, `underwater`, `wall`. Chain your own with `eq`, `ringmod`, `drive`, `chorus`, `reverb`, `varispeed`.
- **Engine as species**: formant = human-like; tract = wet, throaty, animal; blip = toy, pixel, UI; mumble =
  distant, private, behind glass. A cast can mix engines.
- **Emotion per line**: put it in the text (punctuation, capitals, repetition, word length) and nudge
  `range`/`rate`/`tension` per line — anger: tension↑ rate↑ range↑ pitch +2 st; sadness: rate↓ range↓ breath↑
  falling; fear: pitch↑ tremor↑ rate↑ breath↑; joy: range↑ rate↑ pitch +3 st.

Non-speech vocal sounds (growls, purrs, roars, chirps) come from the same parts: a slow rough source
(`pitch` 30–80, `rough` 1) through big `size`, or stick–slip pulses through formant-like resonances
(`physics.md` §6), layered with noise.

## Crowds and background voices

`crowd({ voices, seconds, lines, energy, room })` layers mumble voices of mixed pitch, size and rate with their
own pauses, panned and reverberated. `energy` 0.2 murmur (library, church) → 0.8 excited (market, bar).
Supply `lines` in the scene's language for believable phrase lengths. For a pub, add clinks (`strike` of glass
modes) and chair scrapes (`stickSlipForce`); for a stadium, more voices, long `rt60`, slow swells of level.
Put it behind a wall with `voiceFx(…, 'wall')` or a zone low-pass (`ambience.md`).

## Verifying (`--lens speech`)

| Metric | Speech-like range | If outside |
|---|---|---|
| `syllableRate` | 3–7 /s (blip: up to 12) | too slow → drunk/slow-motion; too fast → chatter |
| `voicedRatio` | 0.4–0.8 (whisper 0) | too high → singing/humming; too low → noise |
| `f0RangeSt` | 4–12 st | < 2 robot; > 15 cartoon |
| `syllabicDepth` | > 0.3 | flat envelope = drone, not speech |
| `articulationOct` | > 0.25 (mumble 0.1–0.2) | no formant movement = a vowel, not talking |
| `pauseShare` | 0.1–0.3 | no pauses = not phrased |

Also check the f0 contour sparkline for the phrase shapes you wrote (rise on `?`, fall on `.`), and
`marks` against the picture if lips or text must sync. These measure prosody-likeness only; whether the
character is *charming* is for ears — offer two or three contrasting takes.
