From cfabc9be18e88cbdd67e02083b3771ac7a52f51c Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 14 Jun 2026 02:12:53 -0500 Subject: [PATCH 1/2] Add Codex task for Piper TTS migration --- CODEX_TASK_PIPER.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 CODEX_TASK_PIPER.md diff --git a/CODEX_TASK_PIPER.md b/CODEX_TASK_PIPER.md new file mode 100644 index 0000000..46c847b --- /dev/null +++ b/CODEX_TASK_PIPER.md @@ -0,0 +1,34 @@ +# Codex task: replace gTTS realtime speech synthesis with Piper + +Repository: trinitron88/ChinTranslator +Base branch: main +Issue: #11 + +Goal +Replace per-utterance gTTS MP3 generation in the realtime Hugging Face Space with local Piper TTS to reduce latency, network dependency, and phone battery drain. + +Context +hf_space/app.py currently calls gTTS, writes an MP3 temp file, reloads it via librosa, converts it to PCM, and yields it back to FastRTC. This works but is slow and network-bound. The project roadmap already calls out Piper as the next step for low-latency local TTS. + +Suggested implementation +- Work primarily in hf_space/app.py and hf_space/requirements.txt. +- Add backend config with environment variables such as TTS_BACKEND, PIPER_MODEL, and PIPER_CONFIG. +- Keep gTTS as fallback while Piper is being tested. +- Implement a speak_piper(text, lang) path for English output in Chin to English mode. +- Return FastRTC-compatible sample rate and int16 PCM audio. +- Avoid shelling out per phrase if a Python API or persistent process is practical; otherwise document the tradeoff. +- English to Chin can remain text-only unless a suitable Chin voice exists. +- Update REALTIME.md and/or README.md with required Space variables and model setup. + +Acceptance criteria +- Chin to English mode speaks English using Piper when configured. +- App still boots if Piper is unavailable and falls back cleanly to gTTS or text-only. +- Per-utterance latency is materially lower than gTTS in local or HF testing. +- No temp MP3 round-trip is required for the Piper path. +- Docs explain how to configure Piper in the Space. + +Suggested validation +- Run or import hf_space/app.py enough to confirm syntax and imports. +- Test the gTTS fallback still behaves like current production. +- Test text-only mode if implemented. +- Test Piper path on a short English phrase and confirm PCM output shape and sample rate are accepted by FastRTC. From 05bd2e1b28bd3efe068ce0f87d20f140dec27358 Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 14 Jun 2026 02:29:59 -0500 Subject: [PATCH 2/2] Add visible app version stamp --- hf_space/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hf_space/app.py b/hf_space/app.py index d0c1562..945b61d 100644 --- a/hf_space/app.py +++ b/hf_space/app.py @@ -61,6 +61,9 @@ CHIN_CODE = "cnh" +APP_VERSION = os.environ.get("APP_VERSION", "v5.0.1") +print(f"[app] version={APP_VERSION}", flush=True) + # Skip translating/speaking when the input is detected as English. Besides being # the requested behavior, this breaks the TTS→mic feedback loop (the English we # speak won't get re-transcribed and echoed). Tunable via env: SKIP_ENGLISH=0 @@ -332,7 +335,7 @@ def _update_transcript(current: str, chin: str, english: str) -> str: server_rtc_configuration=server_rtc_configuration, # Short, one-line title so it doesn't wrap and overlap the record button # on mobile. - ui_args={"title": "Hahka Chin Audio Translator"}, + ui_args={"title": "Hakha Chin Audio Translator"}, ) # Spaces (gradio SDK) serves this `demo` object. Append a mic-sensitivity slider; @@ -375,8 +378,11 @@ def _update_transcript(current: str, chin: str, english: str) -> str: ".button-wrap .mute-button {" " padding: var(--size-2) var(--size-4) !important;" " border-radius: var(--radius-lg) !important; }" + ".app-version { font-size: 0.85rem; opacity: 0.7; text-align: center;" + " margin: -0.25rem 0 0.75rem; }" "" ) + gr.HTML(f"
Build: {APP_VERSION}
") direction = gr.Radio( choices=[("Hakha Chin → English", "cnh2en"), ("English → Hakha Chin", "en2cnh")],