Implement Piper TTS for realtime English (gTTS fallback)#14
Draft
trinitron88 wants to merge 5 commits into
Draft
Implement Piper TTS for realtime English (gTTS fallback)#14trinitron88 wants to merge 5 commits into
trinitron88 wants to merge 5 commits into
Conversation
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>
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the
CODEX_TASK_PIPER.mdplan (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 onTTS_BACKEND(defaultpiper)._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, withPIPER_CONFIG/sibling.onnx.json) orPIPER_VOICEdownloaded fromrhasspy/piper-voices(defaulten_US-lessac-medium).synthesize_stream_raw) and 1.3+ (synthesize→AudioChunk).READMEdocuments the new vars;requirements.txtaddspiper-tts.CODEx_TASK_CACHE.mdthat 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.
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:piper-tts→ setpython_version: "3.11"inhf_space/README.mdfrontmatter, or remove thepiper-ttsline (app falls back to gTTS). Both noted inrequirements.txt.Left as draft until it's confirmed building + speaking on the Space. Test plan: deploy this branch, leave
TTS_BACKENDdefault, confirm the boot log shows✓ Piper voice loaded, and that cnh→en speaks. Compare latency vsTTS_BACKEND=gtts.Refs #11. Supersedes #13 (brief only).
🤖 Generated with Claude Code