Skip to content

feat(audio): let the flagship speak through Lemonade - #6204

Merged
kovtcharov-amd merged 5 commits into
amd:mainfrom
huong8373tt-beep:feat/flagship-tts-tool-6090
Nov 3, 2026
Merged

kovtcharov-amd merged 5 commits into
amd:mainfrom
huong8373tt-beep:feat/flagship-tts-tool-6090

Conversation

@huong8373tt-beep

Copy link
Copy Markdown
Contributor

Summary

Closes #6090.

  • Expose the existing Lemonade Kokoro client as the flagship text_to_speech tool.
  • Refuse missing or not-downloaded TTS models before synthesis; nothing downloads silently during a chat.
  • Support configurable TTS model role, validated Kokoro voices, speed bounds, WAV output, non-empty-file evidence, and sentence-sized long-text synthesis.
  • Preserve the existing tool name for compatibility while making the contract actionable.

Validation

  • tests/unit/test_lemonade_speech.py tests/unit/test_audio_tools.py -q: 67 passed, 1 skipped
  • python -m py_compile on changed Python files: passed
  • git diff --check: passed
  • Black/isort were not installed in this local environment; GitHub Code Quality will run them.
  • No live Lemonade TTS service was available here, so no live integration result is claimed.

Slai Agent Runtime performed the investigation, implementation, and test execution. The account owner authorized this contribution and is responsible for its content.

@github-actions github-actions Bot added audio Audio (ASR/TTS) changes tests Test changes labels Oct 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

This PR makes the flagship's speak-aloud tool safer: it checks the voice and speed, splits long text into chunks, and won't download a speech model mid-chat. The direction is right. But the tool used to fetch the Kokoro model on first use, and now it refuses and tells the user to go to a screen that, as far as I can find, doesn't offer TTS models. A new user who asks GAIA to read something aloud gets an error they can't fix.

What to fix before merge:

  • Give users a way to get the model that actually works. Either have gaia init download Kokoro, or point the error at a real command or screen. As far as I can find, the TUI's model list deliberately filters out TTS models.
  • Test the tool itself, not just the client. The new checks for speed range, .wav extension, empty output and the no-download preflight have no tests at the tool level.
  • Show it working once. The PR says no live Lemonade TTS run was possible. This tool is reachable from the Agent UI, so one real run from a fresh install (model not downloaded) would settle the first point.

Real-world evidence

N/A: no evidence bundle was produced for this PR, and the description says no live Lemonade TTS service was available. This verdict rests on reading the code. I also couldn't run the unit tests here (pytest isn't installed in this runner). The tool's real behaviour, especially on a fresh install, hasn't been exercised.

🔍 Technical details

🟡 Removing the auto-pull leaves new users with no working fix (src/gaia/audio/lemonade_tts.py:266, chat_agent.py:2861)
The old tool called client.ensure_model(), which pulled kokoro-v1 on first use. The new check_model_available() raises "Download it from Settings → Models". That has two problems:

  • gaia init doesn't download a TTS model (no kokoro/tts reference in src/gaia/installer/).
  • tui/internal/lemonade/catalog.go:83 (isChatModel) excludes models labelled tts, so the TUI picker never lists Kokoro.

I couldn't find a Settings → Models TTS path in the webui either. This is CLAUDE.md's cold-state case: it only works on a machine that already has Kokoro cached. Name a command the user can run instead, or add Kokoro to init. The same applies to the "not in its catalog" message at line 254.

🟡 No tool-level tests for the new contract (hub/agents/gaia/python/gaia_agent/chat_agent.py:2790)
The two new tests cover only the client (check_model_available, synthesize_to_wav_long). Nothing covers the tool's new branches:

  • speed outside 0.5–2.0
  • empty text
  • a non-.wav output_path
  • the not-downloaded refusal surfacing as {"status": "error"}
  • the empty-file check
  • model coming from config.tts_model

hub/agents/gaia/python/tests/test_chat_file_tools_allowed_folders.py:88 already calls the tool through the registry, so that pattern extends easily.

🟢 chunks in the result doesn't match the chunks actually sent (chat_agent.py:2880)
(len(text)+1799)//1800 estimates the count from length. _split_text packs by sentence and then hard-splits, so the real number can differ, and text under the limit always yields 1. Report the real count instead, e.g. have synthesize_to_wav_long return (duration, len(pieces)), or drop the field.

🟢 tts_model can't be set by anyone (chat_agent.py:285)
Nothing reads ChatAgentConfig.tts_model from config.json, the CLI or the UI. As shipped it's always None. Wire it up (and document it) or leave it for the PR that needs it.

🟢 The hard split can cut words in half (lemonade_tts.py:192)
The hard split slices at a fixed character offset, so a chunk can end mid-word and Kokoro will mispronounce it. Splitting at the last whitespace before limit would fix that cheaply.

Strengths

  • The exception handling is narrowed from a bare except Exception to specific types. That fits the fail-loudly rule and still turns errors into a structured tool error.
  • The new client test asserts that preflight makes exactly one catalog request, so "no silent download" is checked against the actual request sent.
  • The long-text path checks that the sample rate stays the same across chunks, rather than gluing mismatched audio together.

@github-actions github-actions Bot added llm LLM backend changes cli CLI changes performance Performance-critical changes labels Oct 31, 2026
@huong8373tt-beep

Copy link
Copy Markdown
Contributor Author

Pushed commit 409b7c264 with the remaining TTS review fixes.\n\n- Missing Kokoro now gives the executable remedy gaia download --agent talk; the Talk profile now includes kokoro-v1.\n- Added tool-level tests for invalid speed/empty text/output extension, missing-model errors, and real chunk counts.\n- Long-text splitting prefers whitespace boundaries instead of cutting ordinary words.\n- TTS focused tests: 29 passed, 2 skipped; Black/isort passed.\n\nNo live Lemonade TTS call is claimed because no compatible local server was available.\n\nSlai Agent Runtime performed the investigation, implementation, and test execution. The account owner authorized this contribution and is responsible for its content.

@huong8373tt-beep

Copy link
Copy Markdown
Contributor Author

The current head 6528982b1 now includes the requested tool-level regression coverage (hub/agents/gaia/python/tests/test_chat_tts_tool.py) for invalid speed, empty text, .wav enforcement, missing-model structured errors, empty output, and real chunk counts. The missing-model remedy is executable and present in the shipped CLI/profile: gaia download --agent talk; it does not rely on a nonexistent Settings TTS picker or gaia init. A live Lemonade TTS run is still unavailable in this environment, so none is claimed. The requested authorization disclosure remains in the PR.

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

The tool hardening is good. But adding Kokoro to the talk profile also adds it to gaia init --profile all, and init's model check would then test the speech model as if it were a chat model. On a fresh install with that profile, setup would report Kokoro as a failed model. Two things to fix before merge:

  • Keep gaia init --profile all passing. Either teach init's model verification that a TTS model is not a chat model (skip it, or test it with a short speech request), or keep Kokoro out of the profile list that all collects. Add a test that the all profile's verification doesn't send kokoro-v1 a chat request.
  • Document how to get the voice model. The tool no longer downloads Kokoro on first use. The docs should say to run gaia download --agent talk first, in the flagship guide next to text_to_speech and in the Talk guide.
🔍 Technical details
  • get_required_models("all") on this branch returns ['Gemma-4-E4B-it-GGUF', 'kokoro-v1', 'user.embeddinggemma-300m-GGUF'].
  • InitCommand._test_model_inference (src/gaia/installer/init_command.py) recognises only embedding and SD models by name. Everything else is loaded with ctx_size and sent chat_completions(...), so kokoro-v1 lands in models_failed. _load_model_once / _describe_models also label it role "chat".
  • Docs: docs/guides/gaia.mdx (tool table lists text_to_speech), docs/guides/talk.mdx. The gaia download help now mentions it, but docs/reference/cli.mdx doesn't.
  • Nit: hub/agents/gaia/python/tests/test_chat_tts_tool.py:6 imports MagicMock unused (flake8 F401).
  • CI: the Windows unit failure is test_file_watcher_settle::test_real_watcher_reports_a_copied_file_once_complete, a real-filesystem timing test this PR doesn't touch. The Windows security job was cancelled at the 6-hour runner limit; tests/verify_path_validator.py passes locally on this head in seconds.

kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Nov 3, 2026
…h tool

Merges amd#6204 (the flagship text_to_speech tool) under read-aloud so GAIA
has one way to make speech: the same Lemonade client, voice list and
speed range, and the voice and speed the user picks for reading aloud.

- text_to_speech now defaults to read_aloud_voice and read_aloud_speed
  from ~/.gaia/config.json when the request names neither.
- Its speed bounds come from READ_ALOUD_MIN_SPEED/MAX_SPEED, the range
  the settings already enforce.
Adding Kokoro to the talk profile also put it in `gaia init --profile all`,
whose model check sent every non-embedding model a chat request, so a clean
install reported the voice model as broken. Init now recognises TTS models
from the model registry, checks them by synthesizing one word, and labels
them "speech" in `gaia init --check --load`.

The docs now say to run `gaia download --agent talk` before asking the agent
to read aloud, since the tool no longer downloads Kokoro itself.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Thanks @huong8373tt-beep. The tool hardening is solid. I pushed the two remaining review items onto your branch, so a clean gaia init --profile all now passes with Kokoro in it, and the docs tell users how to get the voice model.

  • Init now checks a speech model by speaking one word instead of sending it a chat request, and gaia init --check --load labels it as speech.
  • The flagship guide, the Talk guide, the CLI reference and the flagship CHANGELOG all say to run gaia download --agent talk before asking the agent to read aloud.
  • I merged main in. The earlier Windows unit failure was an unrelated file-watcher timing test.
🔍 Technical details
  • is_tts_model_id() reads ModelType.TTS from MODELS. _test_model_inference and _load_model_once send a TTS model one LemonadeTTSClient.synthesize("ok") and never call load_model or chat_completions on it.
  • New tests/unit/installer/test_init_verify_tts.py covers these cases: --profile all verification sends kokoro-v1 no chat or load request, a failed or empty speech reply fails verification, and --check --load reports role speech.
  • Removed the unused MagicMock import from test_chat_tts_tool.py (F401).

@github-actions github-actions Bot added the documentation Documentation changes label Nov 3, 2026
kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Nov 3, 2026
…h tool

Merges amd#6204 (the flagship text_to_speech tool) under read-aloud so GAIA
has one way to make speech: the same Lemonade client, voice list and
speed range, and the voice and speed the user picks for reading aloud.

- text_to_speech now defaults to read_aloud_voice and read_aloud_speed
  from ~/.gaia/config.json when the request names neither.
- Its speed bounds come from READ_ALOUD_MIN_SPEED/MAX_SPEED, the range
  the settings already enforce.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 3, 2026
Merged via the queue into amd:main with commit 1e8c786 Nov 3, 2026
63 checks passed
kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Nov 5, 2026
…h tool

Merges amd#6204 (the flagship text_to_speech tool) under read-aloud so GAIA
has one way to make speech: the same Lemonade client, voice list and
speed range, and the voice and speed the user picks for reading aloud.

- text_to_speech now defaults to read_aloud_voice and read_aloud_speed
  from ~/.gaia/config.json when the request names neither.
- Its speed bounds come from READ_ALOUD_MIN_SPEED/MAX_SPEED, the range
  the settings already enforce.
kovtcharov-amd added a commit to rezamuliawijaya/gaia that referenced this pull request Nov 7, 2026
GAIA had a local voice (Kokoro, through Lemonade) but no way to hear a
reply in either app: the agent's `text_to_speech` tool only wrote a WAV
nobody saw. Now every reply in the Agent UI has a speaker button, the
TUI has `/read-aloud`, and both share one voice, speed and "read every
reply" setting in `~/.gaia/config.json`.

- **Agent UI:** a speaker button on each reply (press again to stop).
**Settings › Read aloud** has a voice picker grouped by American or
British English and female or male, with **Preview**, a speed from 0.5×
to 2×, and a toggle to read each reply when it finishes. Code blocks,
links and markdown marks are skipped. Long replies are spoken in pieces,
the next fetched while one plays, so speech starts in about a second
once the voice is loaded. On a PC without the voice model, the first
press says it is downloading (~0.35 GB) instead of showing a bare
spinner.
- **TUI:** `/read-aloud` reads the last reply (again, or `/read-aloud
stop`, stops it). `/voice` lists and sets voice, speed and auto-read.
Playback uses the OS's own player: PowerShell on Windows, `afplay` on
macOS, `pw-play`/`paplay`/`aplay` on Linux.
- **Backend:** `GET/PUT /api/speech/settings`, `GET /api/speech/model`
(is the voice downloaded) and `POST /api/speech` (WAV). Failures say
what broke: 503 when Lemonade is unreachable, 502 when it can't speak,
422 for a bad voice or speed.

**One speech pipeline.** Built on amd#6204 (the agent's `text_to_speech`
tool, now in main): the button, the TUI and the agent's tool share one
Lemonade client, voice list and speed range. With no voice or speed
named, the tool now uses the ones picked for reading aloud.

The `text_to_speech` docstring now says an omitted voice or speed means
the user's choice. Eval category to watch at the next RC: `web_system`
(`text_to_speech`).

The voices speak English only; the settings say so, since Arabic replies
are read with an English accent.

## Test plan
- [x] `pytest tests/unit` — new `test_speech_router.py` (settings round
trip, validation, WAV shape, 502/503) and `test_tui_voices_drift.py`
(TUI voice list matches `KOKORO_VOICES`)
- [x] `npm test` (2,471 tests incl. new store, text-splitting, button
and settings-pane tests) and `npm run test:rtl` with read-aloud settings
and a failed reading, in Arabic light/dark and English
- [x] `go build ./...`, `go vet ./...`, `go test ./...` in `tui/`
- [x] Real Lemonade (private 2026.43.3 instance): `POST /api/speech`
returned 4.5 s of 24 kHz audio (30 s cold, 1.4 s warm); in the Agent UI,
Settings › Read aloud saved a new voice and Preview played to the end
and returned to idle
- [x] Real Windows playback through the TUI's player: a 4.5 s clip
played in 5.2 s; stopping cut it off in 0.5 s
- [x] Screenshots read in English and Arabic, light and dark, and at 390
px
- [x] Both apps end to end against a stand-in Lemonade, in an isolated
GAIA home: a voice and speed set in the Agent UI were used by the TUI's
auto-read; auto-read skipped a failed turn (it used to read the error
out); a speech failure shows the reason; 20 rapid clicks and
`/read-aloud` twice both end idle
- [ ] Reviewer: on a PC with a chat model, press the speaker on a reply
and turn on auto-read; in the TUI, `/read-aloud` and `/voice bm_george`
- [x] Linux playback: in a Debian container, the TUI's player played a
read-aloud WAV through `paplay` on a real PulseAudio daemon (null sink)
to the end, and a cancel stopped it within 0.7 s; `aplay` accepted the
same WAV
- [ ] Reviewer: macOS playback (`afplay`; no Mac was available)

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 12, 2026
…plan

Read-aloud (amd#6489) and the flagship text_to_speech tool (amd#6204) have both
merged, but the plan still treated them as open branches to coordinate with.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audio Audio (ASR/TTS) changes cli CLI changes documentation Documentation changes llm LLM backend changes performance Performance-critical changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(audio): let the flagship speak — a text-to-speech tool on Lemonade

2 participants