How luongxuannhat/nghitts_diagram works
1. Repo shape: two major deployments in one monorepo
- The runtime product is a Vue 3 + Vite browser app deployed to Cloudflare Pages.
- A separate train/ subtree is a Python/Piper training and export toolchain; it is not part of the browser runtime, but it produces the TTS models the app consumes.
2. Main user-facing surfaces
- The frontend has four routes: Vietnamese TTS (/), English TTS (/en), Indonesian TTS (/id), and ASR (/asr).
- src/App.vue provides the shell: language/feature tab bar, share action, and access to the TTS history panel.
3. Frontend subsystem boundaries
- src/views/ holds page-level orchestration:
- VietnameseView.vue for the Vietnamese-specific TTS pipeline.
- LanguageView.vue for the reusable non-Vietnamese TTS page.
- ASRView.vue for microphone/file transcription workflows.
- src/components/ contains UI controls and result panels such as model selection, voice selection, speed, statistics, demo table, audio chunks, and history.
4. TTS runtime architecture
- Speech synthesis runs entirely in the browser.
- The app loads Piper ONNX models into a Web Worker (src/workers/tts-worker.js for Vietnamese, tts-worker-i18n.js for English/Indonesian) and uses ONNX Runtime Web from public/onnx-runtime/.
- The worker streams generated audio chunks back to the UI, which can play them immediately and later merge them into a final WAV result.
5. Vietnamese vs. other-language TTS pipeline
- Vietnamese TTS uses a heavier text-normalization pipeline in src/utils/vietnamese-processor.js, text-cleaner.js, transliterator.js, and related detectors.
- That pipeline handles numeric/date/currency/time/roman-numeral conversions before phonemization and synthesis.
- English and Indonesian use the simpler src/lib/piper-tts-i18n.js path, with less language-specific preprocessing.
6. Model discovery and model delivery boundary
- The browser never hardcodes model binaries; it discovers them through Cloudflare Pages Functions under functions/api/.
- TTS model listing and serving is split by language:
- Vietnamese: /api/models and /api/model/[name].ts
- English/Indonesian: /api/piper/{lang}/models and /api/model/piper/{lang}/{name}
- ASR model listing/serving is separate:
- /api/asr/models
- /api/model/asr/{model}/{name}
- This creates a clear boundary between the static browser app and server-side model catalog/asset delivery.
7. Production storage and local-dev parity
- In production, model files live in Cloudflare R2 and are exposed by the Pages Functions.
- In local development, the same logical model structure is mirrored under public/tts-model/... and public/asr-model/.
- Other static runtime assets are shipped from public/, including the Sherpa-ONNX WASM bundles, Silero VAD ONNX model, demo audio/text pairs, and normalization CSVs.
8. ASR runtime architecture
- ASR is also browser-local and uses Sherpa-ONNX WASM plus Silero VAD.
- public/code/asr-wasm/ contains the ASR/VAD WASM loaders, while public/vad-model/silero-vad/silero_vad.onnx provides voice activity detection.
- The ASR page supports two input flows:
- microphone capture with real-time VAD segmentation
- file upload with decoding, segmentation, and timestamped transcription/SRT export
9. State and persistence boundaries
- TTS generation history is persisted in IndexedDB via src/utils/history-store.js, letting the user replay, download, or copy prior outputs.
- ASR model choice is persisted in localStorage.
- Model caching/detection helpers in src/utils/model-cache.js and model-detector.js keep the browser from repeatedly reloading the same assets.
10. Configuration and routing
- src/router/index.js maps the four main feature routes.
- src/config.js and src/config.json control runtime behavior such as debug mode and roman numeral handling.
- public/_routes.json and wrangler.toml tie the app to Cloudflare Pages deployment behavior and the R2 binding.
11. Training/export subsystem
- train/ is a standalone Piper ecosystem for dataset handling, phonemization, model training, ONNX export, and voice packaging.
- It includes Python modules, C/C++ bindings, tests, and scripts for training/export/server tasks.
- Conceptually, this is the upstream model-production boundary: it generates the .onnx and .onnx.json assets that the browser app later discovers and runs.
12. End-to-end data flow summary
- User input enters the Vue UI → text/audio is prepared in the browser → model metadata is fetched from Pages Functions → model files are streamed from local public/ or R2 → inference runs in Web Workers/WASM → results return to the UI for playback/transcription/download → optional persistence stores history or selected model state.
Main entry points: model Model serving · index.js Router · VietnameseView.vue Vietnamese TTS · LanguageView.vue Other TTS
Components 26
Browser app
Vue 3 + Vite runtime deployed to Cloudflare Pages.
- Main app · Bootstraps the SPA, global styling, and app composition.
src/main.js - App shell · Top-level UI with feature tabs, sharing, and history access.
src/App.vue - Router · Maps the four main feature routes.
src/router/index.js - Vietnamese TTS · Orchestrates Vietnamese synthesis and preprocessing.
src/views/VietnameseView.vue - Other TTS · Reusable English and Indonesian synthesis page.
src/views/LanguageView.vue - ASR view · Microphone and file transcription workflows.
src/views/ASRView.vue - UI controls · Model, voice, speed, stats, demos, audio chunks, and history panels.
src/components - VN processor · Normalization, transliteration, and detector chain for Vietnamese TTS.
src/utils/vietnamese-processor.js - Text cleanup · Shared cleanup path for non-Vietnamese synthesis.
src/utils/text-cleaner.js - I18n TTS core · English and Indonesian browser synthesis path with lighter preprocessing.
src/lib/piper-tts-i18n.js - VN worker · Loads Piper ONNX runtime and streams generated audio chunks back to UI.
src/workers/tts-worker.js - I18n worker · Worker for English and Indonesian synthesis.
src/workers/tts-worker-i18n.js - Piper TTS · Shared browser-side synthesis logic used by both workers.
src/lib/piper-tts.js - ASR runtime · Sherpa-ONNX WASM plus VAD-driven transcription pipeline.
public/code/asr-wasm/sherpa-onnx-asr.js - History store · Persists TTS outputs for replay, download, and copy.
src/utils/history-store.js - Model cache · Avoids repeated reloads and detects available models.
src/utils/model-cache.js
Pages Functions
Model catalog and asset delivery boundary between app and storage.
- Model APIs · Lists and serves TTS and ASR models from the serverless boundary.
functions/api - Model serving · Language-aware model asset routes for TTS and ASR binaries.
functions/api/model
Public assets
Static runtime files shipped with the browser app.
- Runtime assets · ONNX Runtime Web, ASR WASM loaders, demos, and normalization data.
public - TTS models · Local-dev mirror for language models and voices metadata.
public/tts-model - ASR models · Local-dev mirror for ASR models.
- VAD model · Silero VAD ONNX model used by ASR segmentation.
public/vad-model/silero-vad/silero_vad.onnx
Training toolchain
Standalone Piper training, export, and packaging subtree.
- Piper train · Standalone training, export, and packaging toolchain.
train/src/piper - VITS trainer · Core training stack for datasets, losses, and VITS models.
train/src/piper/train/vits - Export tools · ONNX export and voice packaging generators.
train/src/piper/train/export_onnx.py - Voice packaging · Voice metadata, phonemization, and packaged model helpers.
train/src/piper/voice.py
Connections 28
- Main app → App shell: mounts · Main entry renders the SPA shell.
- App shell → Router: navigates · Shell delegates feature switching to router.
- App shell → UI controls: composes · Shell uses shared controls and panels.
- Router → Vietnamese TTS: route / · Vietnamese TTS page.
- Router → Other TTS: routes /en,/id · Reusable non-Vietnamese TTS pages.
- Router → ASR view: route /asr · ASR transcription page.
- Vietnamese TTS → VN processor: preprocesses · Vietnamese text normalization before synthesis.
- Vietnamese TTS → VN worker: sends text · Hands off synthesis to worker.
- Vietnamese TTS → History store: persists results · Stores synthesis history in IndexedDB.
- Other TTS → Text cleanup: cleans text · Shared text cleanup for English and Indonesian.
- Other TTS → I18n worker: sends text · Hands off synthesis to i18n worker.
- Other TTS → Model cache: tracks models · Caches and detects model availability.
- VN worker → Piper TTS: runs · Worker executes shared Piper synthesis core.
- I18n worker → I18n TTS core: runs · I18n worker uses lighter browser synthesis path.
- VN worker → Runtime assets: loads runtime · Uses ONNX Runtime Web and related assets.
- I18n worker → Runtime assets: loads runtime · Uses ONNX Runtime Web assets.
- ASR view → ASR runtime: captures audio · Uses WASM ASR with VAD for microphone and file flows.
- ASR view → VAD model: uses VAD · Voice activity detection model for segmentation.
- ASR view → Model cache: persists choice · Stores selected ASR model in localStorage.
- Model APIs → Model serving: feeds · Catalog endpoints connect to model asset routes.
- Model serving → TTS models: dev mirror · Local development TTS model layout.
- Model serving → ASR models: dev mirror · Local development ASR model layout.
- Model serving → Runtime assets: serves assets · Static bundles and runtime files are delivered to the browser.
- Piper train → VITS trainer: contains · Training package includes VITS model stack.
- Piper train → Export tools: exports · Generates ONNX and packaging artifacts.
- Piper train → Voice packaging: packages · Handles voice metadata and packaging helpers.
- Export tools → Model serving: produces assets for · Training/export outputs become browser-consumable model files.
- Voice packaging → TTS models: targets · Packaged voice artifacts match the runtime model layout.