# ai.audio.generate

Speaks --text as an audio file through a text-to-speech --provider

# ai.audio.generate

```
ai.audio.generate --provider piper --credential TEXT --text TEXT [--voice TEXT] [--speed N] [--option KEY=TEXT…] [--return inline|file] [--store TEXT] [--folder TEXT] [--filename TEXT] [--path TEXT] [--on-conflict error|skip|overwrite] → audio
```

Speaks `--text` as an audio file through a text-to-speech `--provider`. `--provider piper` runs a local Piper voice named by a `tts` credential (the owner puts the voice files in the store; the credential names their keys). `--text` is what to say; `--voice` and `--speed` shape it; the provider's own settings are `--option` keys (piper: volume, lipsync). `--return file` (default) writes a wav at `--path`, or `--folder`/`--filename` (default folder `audio`), and answers `audio: { …FileRef…, format, mime_type, provider, sample_rate, samples, duration_ms }`; `--return inline` writes nothing and answers the bytes as `audio.base64`, which a page plays at once. Keeps the payload.

**Per provider** (`--provider` picks one; each line is generated from its profile):

```
ai.audio.generate --provider piper --credential TEXT --text TEXT [--voice TEXT] [--speed N] [--option volume=N] [--option lipsync=none|basic|timed_words|audio_guided|audio_segmented] [--return inline|file] [--store TEXT] [--folder TEXT] [--filename TEXT] [--path TEXT] [--on-conflict error|skip|overwrite] → audio
```

- `piper` — `--credential` of kind `tts`
  - `--option volume=…` — Loudness multiplier; 1 is as the voice was recorded.
  - `--option lipsync=…` — Mouth cues and word timings in the answer: none (default), basic, timed_words, audio_guided or audio_segmented.


## Flags

- `--provider` (required): Who speaks: piper (a local Piper voice). Literal, never {{ }}.
- `--credential` (required): The provider's credential: for piper, kind tts, naming the store keys of the voice files.
- `--text` (required): What to say — a literal or {{ expr }}.
- `--voice`: The voice: for piper, the speaker id of a multi-speaker model.
- `--speed`: Speed factor: 1 is normal, greater is faster.
- `--option`: A setting of the chosen provider, key=value, repeated. The keys and their types are the provider's profile; an unknown key is refused.
- `--return`: file (default) writes a wav to the store and answers its FileRef; inline writes nothing and answers the bytes as base64. Literal.
- `--store`: The project store to write to: `local`, or the id of an `s3` credential. Saved explicitly when the pipeline is registered (default: the project's default store at that moment)
- `--folder`: Store folder for the audio file (default: audio).
- `--filename`: Audio file name; .wav is added (default: a UUID).
- `--path`: Exact store key for the audio file; overrides --folder and --filename.
- `--on-conflict`: When the target already exists: overwrite, skip or error (default: error)

## Examples

### Read a post aloud

```
| ai.audio.generate --provider piper --credential piper_en --text "{{ input.query.rows[0].body }}" --filename "{{ $trigger.params.slug }}"
```

It answers:

```json
{
  "audio": {
    "__zf_type": "file_ref",
    "backend": "zebfs",
    "store": "local",
    "ref": "audio/hello.wav",
    "filename": "hello.wav",
    "mime": "audio/wav",
    "kind": "audio",
    "size": 88244,
    "sha256": "sha256:…",
    "lifecycle": "durable",
    "origin": "ai.audio.generate",
    "trust": "generated",
    "provider": "piper",
    "format": "wav",
    "mime_type": "audio/wav",
    "sample_rate": 22050,
    "samples": 44100,
    "duration_ms": 2000
  }
}
```

### Bytes for a page, with mouth cues

```
| ai.audio.generate --provider piper --credential piper_en --text "Hello there." --return inline --option lipsync=timed_words
```

`audio.base64` is the wav; `audio.word_timings` and `audio.lipsync.cues` drive an avatar's mouth. Nothing is written to the store.

## Used in

- [TTS API + Frontend Page](/examples/tts-with-page.md)
