Skip to content

Implement Piper TTS for realtime English (gTTS fallback)#14

Draft
trinitron88 wants to merge 5 commits into
mainfrom
feature/piper-tts-impl
Draft

Implement Piper TTS for realtime English (gTTS fallback)#14
trinitron88 wants to merge 5 commits into
mainfrom
feature/piper-tts-impl

Conversation

@trinitron88

Copy link
Copy Markdown
Owner

Implements the CODEX_TASK_PIPER.md plan (supersedes the brief-only PR #13). Replaces the per-phrase gTTS path (Google round-trip → MP3 temp file → librosa reload) with local Piper synthesis for the cnh→en English voice.

What changed (hf_space/app.py)

  • speak() dispatches on TTS_BACKEND (default piper).
  • _speak_piper() loads the voice once (cached) and returns FastRTC-ready (sample_rate, int16 PCM (1,N)) at the model's own rate. Voice source: PIPER_MODEL (local .onnx, with PIPER_CONFIG/sibling .onnx.json) or PIPER_VOICE downloaded from rhasspy/piper-voices (default en_US-lessac-medium).
  • Handles both piper-tts API variants — 1.2.x (synthesize_stream_raw) and 1.3+ (synthesizeAudioChunk).
  • Bulletproof fallback: any Piper failure (dep not installed, model download fail, synth error) → gTTS; Chin (en→cnh) stays text-only. The app always boots and speaks.
  • Docs: README documents the new vars; requirements.txt adds piper-tts.
  • Restored CODEx_TASK_CACHE.md that the base branch had incidentally deleted, to keep this PR scoped to Piper.

Why

gTTS is network-bound and slow per phrase; Piper is local, low-latency, and CPU-light — a good fit for the Space's tight budget, and a step toward the offline goal.

⚠️ Not verified on the Space — please test on deploy

I could not test Piper locally: piper-tts's phonemizer dependency has no wheel in my environment, and it may also lack a Python 3.12 wheel (the Space's pinned version). Two outcomes to watch on deploy:

  • Build fails on piper-tts → set python_version: "3.11" in hf_space/README.md frontmatter, or remove the piper-tts line (app falls back to gTTS). Both noted in requirements.txt.
  • Builds but Piper errors at runtime → handled: it logs once and uses gTTS.

Left as draft until it's confirmed building + speaking on the Space. Test plan: deploy this branch, leave TTS_BACKEND default, confirm the boot log shows ✓ Piper voice loaded, and that cnh→en speaks. Compare latency vs TTS_BACKEND=gtts.

Refs #11. Supersedes #13 (brief only).

🤖 Generated with Claude Code

trinitron88 and others added 3 commits June 14, 2026 02:12
Implements the CODEX_TASK_PIPER plan. Replaces per-phrase gTTS (network
round-trip + MP3 temp-file reload) with local Piper synthesis for the cnh→en
English voice — lower latency, no network dependency, CPU-light.

- hf_space/app.py: speak() now dispatches on TTS_BACKEND (default 'piper').
  _speak_piper() loads a voice once (PIPER_MODEL local .onnx, else PIPER_VOICE
  downloaded from rhasspy/piper-voices; default en_US-lessac-medium) and returns
  FastRTC-ready (sample_rate, int16 PCM (1,N)) at the model's own rate. Handles
  both piper-tts API variants (1.2.x synthesize_stream_raw / 1.3+ synthesize).
  ANY Piper failure (missing dep/model/synth error) falls back to gTTS, and Chin
  (en→cnh) stays text-only — so the app always boots and speaks.
- requirements.txt: add piper-tts, with a note that if its phonemizer lacks a
  py3.12 wheel, pin python_version 3.11 or remove the line (gTTS fallback).
- README: document TTS_BACKEND / PIPER_MODEL / PIPER_VOICE.
- Restore CODEx_TASK_CACHE.md that the base branch had incidentally deleted.

NOT verified on the Space: piper-tts + its phonemizer wheel availability on the
Space's Python is a deploy-and-check step (can't be tested locally). The gTTS
fallback covers runtime failures; a build failure would need the python_version
or requirements tweak noted above.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
trinitron88 and others added 2 commits June 14, 2026 21:42
So a deployed Piper build is identifiable in the UI 'Build:' stamp and logs
instead of showing the stale v5.0.1.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
# Conflicts:
#	hf_space/README.md
#	hf_space/app.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant