termux-stt 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. termux_stt-1.0.0/LICENSE +21 -0
  2. termux_stt-1.0.0/PKG-INFO +436 -0
  3. termux_stt-1.0.0/README.md +416 -0
  4. termux_stt-1.0.0/pyproject.toml +49 -0
  5. termux_stt-1.0.0/setup.cfg +4 -0
  6. termux_stt-1.0.0/setup.py +19 -0
  7. termux_stt-1.0.0/termux_stt/__init__.py +91 -0
  8. termux_stt-1.0.0/termux_stt/audio/__init__.py +4 -0
  9. termux_stt-1.0.0/termux_stt/audio/loader.py +83 -0
  10. termux_stt-1.0.0/termux_stt/audio/mic.py +41 -0
  11. termux_stt-1.0.0/termux_stt/audio/preprocessor.py +92 -0
  12. termux_stt-1.0.0/termux_stt/audio/vad.py +107 -0
  13. termux_stt-1.0.0/termux_stt/cli/__init__.py +4 -0
  14. termux_stt-1.0.0/termux_stt/cli/benchmark.py +46 -0
  15. termux_stt-1.0.0/termux_stt/cli/diarize.py +37 -0
  16. termux_stt-1.0.0/termux_stt/cli/doctor.py +71 -0
  17. termux_stt-1.0.0/termux_stt/cli/listen.py +30 -0
  18. termux_stt-1.0.0/termux_stt/cli/main.py +80 -0
  19. termux_stt-1.0.0/termux_stt/cli/models_cmd.py +21 -0
  20. termux_stt-1.0.0/termux_stt/cli/transcribe.py +55 -0
  21. termux_stt-1.0.0/termux_stt/diarization/__init__.py +5 -0
  22. termux_stt-1.0.0/termux_stt/diarization/clustering.py +109 -0
  23. termux_stt-1.0.0/termux_stt/diarization/mapper.py +50 -0
  24. termux_stt-1.0.0/termux_stt/diarization/xvector.py +26 -0
  25. termux_stt-1.0.0/termux_stt/engine/__init__.py +122 -0
  26. termux_stt-1.0.0/termux_stt/engine/base.py +154 -0
  27. termux_stt-1.0.0/termux_stt/engine/hybrid_engine.py +159 -0
  28. termux_stt-1.0.0/termux_stt/engine/sherpa_engine.py +218 -0
  29. termux_stt-1.0.0/termux_stt/engine/vosk_engine.py +274 -0
  30. termux_stt-1.0.0/termux_stt/engine/whisper_engine.py +330 -0
  31. termux_stt-1.0.0/termux_stt/export/__init__.py +6 -0
  32. termux_stt-1.0.0/termux_stt/export/json_export.py +22 -0
  33. termux_stt-1.0.0/termux_stt/export/result.py +61 -0
  34. termux_stt-1.0.0/termux_stt/export/rttm.py +20 -0
  35. termux_stt-1.0.0/termux_stt/export/srt.py +30 -0
  36. termux_stt-1.0.0/termux_stt/export/vtt.py +30 -0
  37. termux_stt-1.0.0/termux_stt/models/__init__.py +4 -0
  38. termux_stt-1.0.0/termux_stt/models/hub.py +126 -0
  39. termux_stt-1.0.0/termux_stt/models/quantization.py +39 -0
  40. termux_stt-1.0.0/termux_stt/models/registry.py +54 -0
  41. termux_stt-1.0.0/termux_stt/platform/__init__.py +4 -0
  42. termux_stt-1.0.0/termux_stt/platform/hardware.py +97 -0
  43. termux_stt-1.0.0/termux_stt/platform/installer.py +92 -0
  44. termux_stt-1.0.0/termux_stt/platform/mobile_guard.py +76 -0
  45. termux_stt-1.0.0/termux_stt/platform/process_pool.py +65 -0
  46. termux_stt-1.0.0/termux_stt.egg-info/PKG-INFO +436 -0
  47. termux_stt-1.0.0/termux_stt.egg-info/SOURCES.txt +58 -0
  48. termux_stt-1.0.0/termux_stt.egg-info/dependency_links.txt +1 -0
  49. termux_stt-1.0.0/termux_stt.egg-info/entry_points.txt +3 -0
  50. termux_stt-1.0.0/termux_stt.egg-info/requires.txt +5 -0
  51. termux_stt-1.0.0/termux_stt.egg-info/top_level.txt +1 -0
  52. termux_stt-1.0.0/tests/test_audio_preprocessor.py +8 -0
  53. termux_stt-1.0.0/tests/test_cli.py +8 -0
  54. termux_stt-1.0.0/tests/test_diarization.py +11 -0
  55. termux_stt-1.0.0/tests/test_export_formats.py +22 -0
  56. termux_stt-1.0.0/tests/test_hybrid_engine.py +5 -0
  57. termux_stt-1.0.0/tests/test_model_hub.py +8 -0
  58. termux_stt-1.0.0/tests/test_sherpa_engine.py +5 -0
  59. termux_stt-1.0.0/tests/test_vosk_engine.py +5 -0
  60. termux_stt-1.0.0/tests/test_whisper_engine.py +8 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Eunho Kim (@uno-km)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,436 @@
1
+ Metadata-Version: 2.4
2
+ Name: termux-stt
3
+ Version: 1.0.0
4
+ Summary: Android on-device STT framework for Termux β€” whisper.cpp, vosk, sherpa-onnx unified
5
+ Author: Eunho Kim (@uno-km)
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/uno-km/termux-stt
8
+ Project-URL: Repository, https://github.com/uno-km/termux-stt
9
+ Project-URL: Documentation, https://github.com/uno-km/termux-stt#readme
10
+ Project-URL: Issues, https://github.com/uno-km/termux-stt/issues
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest; extra == "dev"
16
+ Requires-Dist: ruff; extra == "dev"
17
+ Requires-Dist: mypy; extra == "dev"
18
+ Dynamic: license-file
19
+ Dynamic: requires-python
20
+
21
+ # Termux-STT
22
+
23
+ <div align="center">
24
+
25
+ ```
26
+ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ•— β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
27
+ β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•”β•β•β•β•β•β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β•šβ•β•β–ˆβ–ˆβ•”β•β•β•
28
+ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘
29
+ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β• β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β•šβ•β•β•β•β•β•šβ•β•β•β•β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘
30
+ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β• β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘
31
+ β•šβ•β• β•šβ•β•β•β•β•β•β•β•šβ•β• β•šβ•β•β•šβ•β• β•šβ•β• β•šβ•β•β•β•β•β• β•šβ•β• β•šβ•β• β•šβ•β•β•β•β•β•β• β•šβ•β• β•šβ•β•
32
+ ```
33
+
34
+ **Production-Grade On-Device Speech-to-Text & Speaker Diarization Framework for Android Termux**
35
+ *Dual-Engine Architecture (Python & Node.js / TypeScript) with Native Bionic ARM64 Acceleration & 0 PyTorch Dependency*
36
+
37
+ <p align="center">
38
+ <a href="https://pypi.org/project/termux-stt/"><img src="https://img.shields.io/pypi/v/termux-stt.svg?color=blue&style=for-the-badge&logo=pypi&logoColor=white" alt="PyPI Version" /></a>
39
+ <a href="https://www.npmjs.com/package/termux-stt"><img src="https://img.shields.io/npm/v/termux-stt.svg?color=red&style=for-the-badge&logo=npm&logoColor=white" alt="npm Version" /></a>
40
+ <a href="https://uno-km.github.io/termux-stt/showcase.html"><img src="https://img.shields.io/badge/Live_Showcase-β–Ά_Audio_Player-00f5d4?style=for-the-badge&logo=googlechrome&logoColor=0b132b" alt="Live Audio Showcase" /></a>
41
+ <a href="https://uno-km.github.io/termux-stt/"><img src="https://img.shields.io/badge/Docs-uno--km.github.io-004499?style=for-the-badge&logo=googlechrome&logoColor=white" alt="Live Docs" /></a>
42
+ <a href="https://github.com/uno-km/termux-stt/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-green.svg?style=for-the-badge" alt="License" /></a>
43
+ </p>
44
+
45
+ <p align="center">
46
+ <img src="https://img.shields.io/badge/Platform-Android%20Termux%20(ARM64%2Faarch64)-00887A?style=flat-square&logo=android&logoColor=white" alt="Platform" />
47
+ <img src="https://img.shields.io/badge/Engines-whisper.cpp%20%7C%20Vosk%20%7C%20Sherpa--ONNX-38bdf8?style=flat-square" alt="Engines" />
48
+ <img src="https://img.shields.io/badge/Diarization-128d%20X--Vector%20+%20Pure%20Python-a855f7?style=flat-square" alt="Diarization" />
49
+ <img src="https://img.shields.io/badge/RAM-Under%20350MB%20(Tiny%2FBase)-10b981?style=flat-square&logo=shield&logoColor=white" alt="RAM" />
50
+ <img src="https://img.shields.io/badge/Python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-f59e0b?style=flat-square&logo=python&logoColor=white" alt="Python" />
51
+ <img src="https://img.shields.io/badge/Node.js-16%20%7C%2018%20%7C%2020%20%7C%2022-3178c6?style=flat-square&logo=nodedotjs&logoColor=white" alt="Node" />
52
+ </p>
53
+
54
+ <br/>
55
+
56
+ **[🎧 Live Audio Showcase & Demo](https://uno-km.github.io/termux-stt/showcase.html)** β€’ **[πŸ“– Official Documentation Site](https://uno-km.github.io/termux-stt/)** β€’ **[⚑ Quickstart](#1-quick-scenario-playbook)** β€’ **[πŸ›οΈ Architecture](#2-why-termux-stt-architectural-pillars)** β€’ **[πŸ“Š Benchmarks](#3-empirical-benchmarks-galaxy-a35--exynos-1380)** β€’ **[πŸ” 15-Part Blog Series](#7-15-part-empirical-research-blog-series)**
57
+
58
+ </div>
59
+
60
+ ---
61
+
62
+ ## πŸŽ™οΈ 단 3μ€„λ‘œ λλ‚΄λŠ” μ•ˆλ“œλ‘œμ΄λ“œ Termux μ˜¨λ””λ°”μ΄μŠ€ μŒμ„±μΈμ‹
63
+
64
+ ```python
65
+ from termux_stt import create_engine
66
+
67
+ # 1. μ—”μ§„ μ΄ˆκΈ°ν™” (졜초 1회 λͺ¨λΈ μžλ™ λ‹€μš΄λ‘œλ“œ 및 캐싱)
68
+ engine = create_engine("whisper", model="base", lang="en")
69
+
70
+ # 2. μ˜€λ””μ˜€ 전사 및 μžλ§‰ 생성 (WAV, MP3, M4A, FLAC, OGG μžλ™ 16kHz λ³€ν™˜)
71
+ result = engine.transcribe("speech.mp3")
72
+
73
+ print(result.text) # 전체 ν…μŠ€νŠΈ
74
+ print(result.to_srt()) # ν‘œμ€€ SRT μžλ§‰
75
+ ```
76
+
77
+ ```bash
78
+ # λ˜λŠ” ν„°λ―Έλ„μ—μ„œ 1쀄 CLI μ‹€ν–‰
79
+ termux-stt transcribe --engine whisper --model base speech.mp3
80
+ ```
81
+
82
+ ---
83
+
84
+ ## 🎧 Live Audio Showcase & On-Device Transcription Proof
85
+
86
+ > **[β–Ά μ›Ή λΈŒλΌμš°μ €μ—μ„œ μ‹€μ‹œκ°„ μŒμ„± 및 동기화 μžλ§‰ μ²΄ν—˜ν•˜κΈ° (Live Audio Showcase)](https://uno-km.github.io/termux-stt/showcase.html)**
87
+
88
+ ### 1. μ‹€μΈ‘ μ˜€λ””μ˜€ μŠ€νŽ™ & 전사 νƒ€μž„λΌμΈ
89
+
90
+ * **μž…λ ₯ μ˜€λ””μ˜€**: `continuous_speech.wav` (37.91초, 16000Hz Mono PCM)
91
+ * **μΆ”λ‘  μ—”μ§„**: `whisper.cpp Base` (On-Device Local CPU)
92
+ * **처리 μ‹œκ°„**: **32.79초** (RTF: **0.865x**, μ‹€μ‹œκ°„λ³΄λ‹€ 빠름)
93
+ * **λ¬Έμž₯ 반볡λ₯ **: **0%** (λͺ¨λ“  λ°œν™” ꡬ간이 각기 λ‹€λ₯Έ λ‚΄μš©μœΌλ‘œ κ³ μœ ν•˜κ²Œ 전사됨)
94
+
95
+ | No. | νƒ€μž„μŠ€νƒ¬ν”„ (μ‹œμž‘ β†’ μ’…λ£Œ) | μ „μ‚¬λœ λ¬Έμž₯ (Transcribed Text) |
96
+ | :---: | :---: | :--- |
97
+ | **01** | `00:00.00 β†’ 00:09.36` | *"And so my fellow Americans, ask not what your country can do for you, ask what you can"* |
98
+ | **02** | `00:09.36 β†’ 00:11.60` | *"do for your country."* |
99
+ | **03** | `00:11.60 β†’ 00:16.18` | *He hoped there would be stew for dinner, turnips and carrots and bruised potatoes and* |
100
+ | **04** | `00:16.18 β†’ 00:22.00` | *fat mutton pieces to be ladled out in thick, peppered flour-fatten sauce.* |
101
+ | **05** | `00:22.00 β†’ 00:25.36` | *Stuff it into you, his belly counseled him.* |
102
+ | **06** | `00:25.36 β†’ 00:29.88` | *After early nightfall, the yellow lamps would light up here and there, the squalid quarter* |
103
+ | **07** | `00:29.88 β†’ 00:37.14` | *of the brothels.* |
104
+
105
+ ### 2. μžλ™ μƒμ„±λœ SRT μžλ§‰ 파일
106
+
107
+ ```srt
108
+ 1
109
+ 00:00:00,000 --> 00:00:09,360
110
+ "And so my fellow Americans, ask not what your country can do for you, ask what you can
111
+
112
+ 2
113
+ 00:00:09,360 --> 00:00:11,600
114
+ do for your country."
115
+
116
+ 3
117
+ 00:00:11,600 --> 00:00:16,180
118
+ He hoped there would be stew for dinner, turnips and carrots and bruised potatoes and
119
+
120
+ 4
121
+ 00:00:16,180 --> 00:00:22,000
122
+ fat mutton pieces to be ladled out in thick, peppered flour-fatten sauce.
123
+
124
+ 5
125
+ 00:00:22,000 --> 00:00:25,360
126
+ Stuff it into you, his belly counseled him.
127
+
128
+ 6
129
+ 00:00:25,360 --> 00:00:29,880
130
+ After early nightfall, the yellow lamps would light up here and there, the squalid quarter
131
+
132
+ 7
133
+ 00:00:29,880 --> 00:00:37,140
134
+ of the brothels.
135
+ ```
136
+
137
+ ---
138
+
139
+ ## πŸ’‘ What is termux-stt?
140
+
141
+ `termux-stt` is an all-in-one, production-ready speech-to-text and speaker diarization framework engineered natively for **Android Termux (ARM64 / aarch64)**.
142
+
143
+ Standard mobile STT setups force developers to endure 30+ minutes of manual CMake builds, broken PyPI wheels on Android Bionic, 2GB+ PyTorch binaries that trigger Android Low Memory Killer (OOM), and broken platform guards.
144
+
145
+ **`termux-stt` eliminates all friction with a 3-line unified API:**
146
+ - **Zero-PyTorch Dependency**: Replaces heavy ML frameworks with C++ binary subprocess isolation and Pure Python clustering math.
147
+ - **Multi-Engine Unification**: Run `whisper.cpp`, `Vosk`, or `Sherpa-ONNX` via the exact same `create_engine()` interface.
148
+ - **Built-in Hybrid Diarization**: Combines Vosk 128d X-Vector voice fingerprints with Whisper STT under 1.5 GB RAM.
149
+ - **Empirically Proven**: Engineered from 15 comprehensive benchmarks on Samsung Galaxy A35 (Exynos 1380, 6GB RAM).
150
+
151
+ ---
152
+
153
+ ## 1. Quick Scenario Playbook
154
+
155
+ ### [Install] Scenario 1: Clean Install (Fresh Setup on Android Termux)
156
+
157
+ #### [Python] Python (`pip`):
158
+ ```bash
159
+ # 1. Grant Storage & Microphone Permissions in Termux
160
+ termux-setup-storage
161
+
162
+ # 2. Install Dependencies & Provision Native Engines
163
+ pkg update -y && pkg install python clang make cmake git ffmpeg termux-api -y
164
+ pip install termux-stt && termux-stt-install
165
+ ```
166
+
167
+ #### [Node.js] Node.js / TypeScript (`npm`):
168
+ ```bash
169
+ # 1. Grant Storage & Microphone Permissions
170
+ termux-setup-storage
171
+
172
+ # 2. Install Dependencies & Provision Native Engines
173
+ pkg update -y && pkg install nodejs-lts clang make cmake git ffmpeg termux-api -y
174
+ npm install -g termux-stt && npx termux-stt install
175
+ ```
176
+
177
+ ---
178
+
179
+ ### [Instant] Scenario 2: Instant Transcription (Ready to Run)
180
+
181
+ #### Option A: One-Line CLI
182
+ ```bash
183
+ # Transcribe audio file with default Whisper engine (Korean)
184
+ termux-stt transcribe meeting.wav
185
+
186
+ # Export directly to Subtitles (SRT or VTT)
187
+ termux-stt transcribe --format srt meeting.wav > subtitles.srt
188
+
189
+ # Use ultra-fast Vosk engine
190
+ termux-stt transcribe --engine vosk --model small-ko voice_memo.wav
191
+ ```
192
+
193
+ #### Option B: Python SDK Integration
194
+ ```python
195
+ from termux_stt import create_engine
196
+
197
+ # 1. Initialize Engine (auto-downloads model on first call)
198
+ engine = create_engine("whisper", model="base", lang="ko")
199
+
200
+ # 2. Transcribe Audio
201
+ result = engine.transcribe("meeting.wav")
202
+
203
+ print("Transcript:", result.text)
204
+ print("Detected Language:", result.language)
205
+ print("Duration:", f"{result.duration:.2f}s")
206
+ ```
207
+
208
+ #### Option C: Node.js / TypeScript Integration
209
+ ```javascript
210
+ const { createEngine } = require("termux-stt");
211
+
212
+ async function main() {
213
+ const engine = createEngine("whisper", { model: "base", lang: "ko" });
214
+ const result = await engine.transcribe("meeting.wav");
215
+
216
+ console.log("Transcript:", result.text);
217
+ console.log("SRT Subtitles:\n", result.toSrt());
218
+ }
219
+ main();
220
+ ```
221
+
222
+ ---
223
+
224
+ ### [Streaming] Scenario 3: Real-Time Microphone Streaming
225
+
226
+ Speak into your smartphone microphone and receive real-time transcribed text with sub-second latency:
227
+
228
+ ```python
229
+ from termux_stt import create_engine
230
+
231
+ # Use ultra-lightweight Tiny model (RTF 0.80 on Exynos 1380)
232
+ engine = create_engine("whisper", model="tiny", lang="ko")
233
+
234
+ print("πŸŽ™οΈ Listening... Speak into your phone microphone (Ctrl+C to stop)")
235
+ for segment in engine.stream_mic():
236
+ print(f"[{segment.start:.1f}s -> {segment.end:.1f}s] {segment.text}")
237
+ ```
238
+
239
+ ---
240
+
241
+ ### [Diarize] Scenario 4: Hybrid Speaker Diarization ("Who Spoke When?")
242
+
243
+ Run high-precision speaker diarization without PyTorch or CUDA:
244
+
245
+ ```python
246
+ from termux_stt import create_engine
247
+
248
+ # Hybrid Pipeline: Vosk 128d X-Vector + Whisper STT + Pure Python K-Means
249
+ engine = create_engine("hybrid", lang="ko", num_speakers=2)
250
+ result = engine.diarize("interview.wav")
251
+
252
+ for seg in result.segments:
253
+ print(f"[{seg.speaker}] ({seg.start:.1f}s - {seg.end:.1f}s): {seg.text}")
254
+ ```
255
+
256
+ *Output Example:*
257
+ ```text
258
+ [Speaker_0] (0.0s - 3.5s): 였늘 경제 λΈŒλ¦¬ν•‘μ„ μ‹œμž‘ν•˜κ² μŠ΅λ‹ˆλ‹€.
259
+ [Speaker_1] (3.8s - 7.2s): λ„€, 였늘 μ½”μŠ€ν”Ό μ§€μˆ˜κ°€ 외ꡭ인 순맀수둜 μƒμŠΉ λ§ˆκ°ν–ˆμŠ΅λ‹ˆλ‹€.
260
+ [Speaker_0] (7.5s - 10.1s): λ°˜λ„μ²΄ μ„Ήν„° 동ν–₯은 μ–΄λ–€κ°€μš”?
261
+ ```
262
+
263
+ ---
264
+
265
+ ## 2. πŸ›οΈ Why termux-stt? Architectural Pillars
266
+
267
+ ```
268
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
269
+ β”‚ termux-stt Architecture β”‚
270
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
271
+ β”‚ User Interface Layer β”‚ Engine Abstraction β”‚ Output / Export Layer β”‚
272
+ β”‚ β€’ Python API β”‚ β€’ EngineRegistry β”‚ β€’ JSON / SRT / VTT β”‚
273
+ β”‚ β€’ Node.js API β”‚ β€’ create_engine() β”‚ β€’ RTTM (Diarization) β”‚
274
+ β”‚ β€’ CLI (termux-stt) β”‚ β€’ ModelHub & Cache β”‚ β€’ Streaming Callback β”‚
275
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
276
+ β”‚ Core Pipeline Layer β”‚
277
+ β”‚ Audio Loader (7 Formats) βž” Preprocessor (16kHz Mono) βž” Silero-VAD Filter β”‚
278
+ β”‚ βž” Multi-Engine STT (whisper.cpp / Vosk / Sherpa-ONNX) β”‚
279
+ β”‚ βž” Hybrid Diarizer (128d X-Vector βž” Pure Python Cosine/K-Means βž” Time Align)β”‚
280
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
281
+ β”‚ Platform & Process Isolation β”‚
282
+ β”‚ β€’ Subprocess Isolation (Host Python never crashes on C++ Segfault) β”‚
283
+ β”‚ β€’ MobileGuard (WakeLock, Doze Mode Bypass, Phantom Process Killer Shield) β”‚
284
+ β”‚ β€’ Bionic ARM64 NEON & FP16 SIMD Acceleration β”‚
285
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
286
+ ```
287
+
288
+ 1. **Subprocess Isolation**: C++ inference runs in isolated native subprocesses. Memory errors or Segfaults never kill the host Python/Node.js application.
289
+ 2. **Pure Python Clustering**: Cosine distance matrix and K-Means clustering are implemented with 0 external dependencies (`numpy` / `scikit-learn` optional, not required).
290
+ 3. **Automated Android Bionic Fixes**: Solves `sys.platform = 'linux'` spoofing, libvosk CFFI extraction, and ffmpeg audio format normalization (`16kHz / 1ch / PCM s16le`) under the hood.
291
+ 4. **Mobile Battery & CPU Guard**: Manages Android WakeLocks and background task states to prevent process termination when the screen locks.
292
+
293
+ ---
294
+
295
+ ## 3. πŸ“Š Empirical Benchmarks (Galaxy A35 / Exynos 1380)
296
+
297
+ > *Measured on Samsung Galaxy A35 5G (Exynos 1380 4x A78 + 4x A55, 6GB RAM, Android 14 Termux).*
298
+
299
+ | Engine / Pipeline | Model | Peak RAM | RTF (Speed) | KO Accuracy | Diarization Support | Termux Rating |
300
+ | :--- | :--- | :---: | :---: | :---: | :---: | :---: |
301
+ | **whisper.cpp** | `ggml-tiny` (39M) | **~150 MB** | **0.80** | 85% | ❌ External | ⭐⭐⭐⭐⭐ |
302
+ | **whisper.cpp** | `ggml-base` (74M) | ~250 MB | 1.20 | 88% | ❌ External | ⭐⭐⭐⭐ |
303
+ | **whisper.cpp** | `ggml-medium` (769M) | ~1.5 GB | 3.40 | **95%+** | ❌ External | ⭐⭐⭐ (Golden Acc) |
304
+ | **Vosk** | `small-ko-0.22` (42M) | **~100 MB** | **0.25** | 78% | βœ… 128d X-Vector | ⭐⭐⭐ |
305
+ | **Sherpa-ONNX** | `Zipformer` | ~300 MB | **0.42** | 86% | βœ… CAM++ | ⭐⭐⭐⭐ |
306
+ | **Pyannote.audio 3.1** | `diarization-3.1` | **> 3.5 GB** | 2.80~3.50 | N/A | βœ… Gold Standard | ❌ OOM Crashes |
307
+ | **termux-stt (Hybrid)** | `Vosk + Whisper Base`| **~350 MB** | **1.45** | **92%+** | **βœ… Built-in K-Means** | **⭐⭐⭐⭐⭐ (Recommended)** |
308
+
309
+ ---
310
+
311
+ ## 4. βš™οΈ Engine Comparison Matrix
312
+
313
+ | Feature | `whisper.cpp` | `Vosk` | `Sherpa-ONNX` | `Hybrid (Vosk+Whisper)` |
314
+ | :--- | :---: | :---: | :---: | :---: |
315
+ | **Primary Strength** | Highest Text Accuracy | Ultra-Low RAM & Fast | Ultra-Low Latency | **STT + Diarization Combined** |
316
+ | **Memory Footprint** | 150MB ~ 1.5GB | **< 100MB** | 300MB ~ 500MB | **~ 350MB** |
317
+ | **Real-Time Factor (RTF)** | 0.80 (Tiny) | **0.25 (Blazing)** | **0.42 (Fast)** | 1.45 (Full Pipeline) |
318
+ | **Speaker Diarization** | ❌ None | ⚠️ Basic X-Vector | ⚠️ CAM++ C++ | **βœ… High-Precision Aligned** |
319
+ | **Recommended Use Case** | Quality Transcripts | Embedded / Low Spec | Live Voice Assistant | **Meetings / Interviews** |
320
+
321
+ ---
322
+
323
+ ## 5. πŸ“š Complete API Reference Summary
324
+
325
+ ### Python API
326
+
327
+ ```python
328
+ import termux_stt
329
+
330
+ # Create Engine
331
+ engine = termux_stt.create_engine(
332
+ engine="whisper", # "whisper" | "vosk" | "sherpa" | "hybrid"
333
+ model="base", # "tiny" | "base" | "small" | "medium" | "custom"
334
+ lang="ko", # ISO 639-1 language code
335
+ num_speakers=0, # 0 = disabled, 2+ = enable diarization
336
+ threads=4, # CPU threads (defaults to big cores count)
337
+ vad=True, # Enable Silero-VAD silence stripping
338
+ quantization="q5_1" # "f16" | "q8_0" | "q5_1" | "q4_0"
339
+ )
340
+
341
+ # Transcribe File
342
+ result = engine.transcribe("audio.wav")
343
+ # Returns: TranscriptResult(text=str, segments=List[Segment], language=str, duration=float)
344
+
345
+ # Export Methods
346
+ result.to_json() # Structured JSON string
347
+ result.to_srt() # Standard SRT subtitle format
348
+ result.to_vtt() # WebVTT subtitle format
349
+ result.to_rttm() # NIST RTTM diarization format
350
+
351
+ # Stream Microphone
352
+ for seg in engine.stream_mic(duration=30.0):
353
+ print(f"[{seg.speaker}] {seg.text}")
354
+
355
+ # Speaker Diarization
356
+ diar_result = engine.diarize("meeting.wav", num_speakers=2)
357
+ ```
358
+
359
+ ### CLI Reference
360
+
361
+ ```bash
362
+ # General Syntax
363
+ termux-stt [COMMAND] [OPTIONS] [FILE]
364
+
365
+ # Commands
366
+ termux-stt transcribe [FILE] # Transcribe audio file
367
+ termux-stt listen # Real-time microphone transcription
368
+ termux-stt diarize [FILE] # Perform speaker diarization
369
+ termux-stt models list # List installed and available models
370
+ termux-stt models download [M] # Download specific model
371
+ termux-stt doctor # Run hardware and environment diagnostics
372
+ termux-stt benchmark # Run performance benchmark suite
373
+ ```
374
+
375
+ ---
376
+
377
+ ## 6. πŸ› οΈ Troubleshooting & Android FAQs
378
+
379
+ ### Q1: `pip install vosk` fails with CMake or wheel error on Android
380
+ * **Cause**: Vosk does not publish official prebuilt aarch64-android wheels on PyPI.
381
+ * **Solution**: `termux-stt-install` automatically extracts `libvosk.so` from the official Android AAR and generates the CFFI bindings.
382
+
383
+ ### Q2: Whisper crashes on 44.1kHz stereo MP3/M4A files
384
+ * **Cause**: Whisper models strictly require single-channel 16,000Hz 16-bit PCM WAV.
385
+ * **Solution**: `termux-stt` automatically runs `ffmpeg` normalization on any audio format (`mp3`, `m4a`, `flac`, `ogg`, `opus`, `webm`).
386
+
387
+ ### Q3: Process killed after 10 minutes in background
388
+ * **Cause**: Android Phantom Process Killer terminates background tasks.
389
+ * **Solution**: Enable Termux WakeLock (`termux-wake-lock`) and disable battery optimization for Termux in Android Settings.
390
+
391
+ ---
392
+
393
+ ## 7. πŸ” 15-Part Empirical Research Blog Series
394
+
395
+ This framework is built upon the exhaustive 15-part research series published on [Eunho Kim's Technical Blog (μš°λ…Έν‚΄ ν‹°μŠ€ν† λ¦¬)](https://uno-kim.tistory.com/):
396
+
397
+ 1. [[Whisper.cpp] #1. Edge Agent AI: Whisper.cpp Speech Processing (Base vs Tiny)](https://uno-kim.tistory.com/467)
398
+ 2. [[Audio Extraction] #2. Extracting Specific Audio Segments on Android](https://uno-kim.tistory.com/468)
399
+ 3. [[Whisper.cpp] #3. Korean STT Conversion Comparison (4 Models)](https://uno-kim.tistory.com/469)
400
+ 4. [[Comparison-1] #4. STT + Speaker Diarization: 3 Lightweight Engines + Pyannote](https://uno-kim.tistory.com/472)
401
+ 5. [[Comparison-2] #5. Sherpa-ONNX Execution, Diarization, and Troubleshooting](https://uno-kim.tistory.com/473)
402
+ 6. [[Comparison-3] #6. Speaker Diarization using Pyannote Model](https://uno-kim.tistory.com/471)
403
+ 7. [[Pyannote] Troubleshooting Diarization in Mobile/Termux/ARM Environments](https://uno-kim.tistory.com/470)
404
+ 8. [[Comparison-4] #7. Vosk Execution, Speaker Diarization, and Troubleshooting](https://uno-kim.tistory.com/475)
405
+ 9. [[Vosk] Troubleshooting Vosk in Mobile/Termux/ARM Environments](https://uno-kim.tistory.com/474)
406
+ 10. [[Comparison-5] #8. Vosk / Pyannote / Sherpa-ONNX / Whisper.cpp Comprehensive Comparison](https://uno-kim.tistory.com/476)
407
+ 11. [[Comparison-6] #9. Vosk + Whisper.cpp Hybrid Pipeline & X-Vector Diarization](https://uno-kim.tistory.com/477)
408
+ 12. [[Development-1] #10. Large-Scale Batch Automation & Task Management Architecture](https://uno-kim.tistory.com/478)
409
+ 13. [[Comparison-7] #11. STT + Diarization Final: Small vs Turbo & Optimization Magic (4-Model Benchmark)](https://uno-kim.tistory.com/479)
410
+ 14. [[Development-2] #12. Domain-Specific STT Training: Whisper Tiny Fine-Tuning on CPU](https://uno-kim.tistory.com/480)
411
+ 15. [[Comparison-8] #13. Vanilla Model vs Custom Fine-Tuned Model (Economics/News Domain)](https://uno-kim.tistory.com/481)
412
+
413
+ ---
414
+
415
+ ## 🌌 The AMEVA Mobile AI & Automation Ecosystem
416
+
417
+ * **🎨 [Termux-Diffusion](https://github.com/uno-km/termux-diffusion)** ([PyPI](https://pypi.org/project/termux-diffusion/) | [npm](https://www.npmjs.com/package/termux-diffusion) | [Docs](https://uno-km.github.io/termux-diffusion/)): Production on-device Stable Diffusion image generation for Android Termux.
418
+ * **🌐 [Termux-Playwright](https://github.com/uno-km/termux-playwright-demo)** ([PyPI](https://pypi.org/project/termux-playwright/) | [npm](https://www.npmjs.com/package/termux-playwright) | [Docs](https://uno-km.github.io/termux-playwright-demo/)): Production headless Chromium browser automation & scraping for Android Termux.
419
+ * **🧠 [termux-train](https://github.com/uno-km/termux-train)**: On-device Autograd deep learning training & LoRA fine-tuning for Android Termux.
420
+ * **πŸ–₯️ [AMEVA Workstation Web](https://github.com/uno-km/AMEVA-Workstation-Web)** ([Live Demo](https://ameva-workstation-web-core.vercel.app/)): 100% on-device WebGPU AI workspace & multimedia document intelligence.
421
+ * **⚑ [AMEVA-Forge](https://github.com/uno-km/ameva-forge)** ([Docs](https://uno-km.github.io/ameva-forge/)): Real-time WebGPU 3D neural studio & visualization engine.
422
+
423
+ ---
424
+
425
+ ## βš–οΈ Disclaimer (λ©΄μ±… μ‘°ν•­)
426
+
427
+ > **Disclaimer:**
428
+ > *termux-stt is an independent open-source project developed for the Android Termux environment and is not officially affiliated with, endorsed by, or sponsored by the Termux project, OpenAI, or any other third party.*
429
+ >
430
+ > *(λ³Έ ν”„λ‘œμ νŠΈλŠ” μ•ˆλ“œλ‘œμ΄λ“œ Termux ν™˜κ²½μ„ μœ„ν•΄ 개발된 독립적인 μ˜€ν”ˆμ†ŒμŠ€ 라이브러리이며, Termux 곡식 ν”„λ‘œμ νŠΈ, OpenAI 및 기타 제3μžμ™€ 직접적인 제휴 관계가 μ•„λ‹™λ‹ˆλ‹€.)*
431
+
432
+ ---
433
+
434
+ ## πŸ“„ License
435
+
436
+ Released under the **MIT License**. Maintained by **uno-km (μŒ©μ΄ˆλ³΄μ½”λ”©λ‹¨) / Eunho Kim**.