termux-stt 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +416 -0
- package/bin/termux-stt.js +20 -0
- package/index.d.ts +62 -0
- package/index.js +33 -0
- package/lib/engine.js +92 -0
- package/lib/hybrid.js +64 -0
- package/lib/vosk.js +60 -0
- package/lib/whisper.js +66 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -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.
|
package/README.md
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
# Termux-STT
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
████████╗███████╗██████╗ ███╗ ███╗██╗ ██╗██╗ ██╗ ███████╗████████╗████████╗
|
|
7
|
+
╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║ ██║╚██╗██╔╝ ██╔════╝╚══██╔══╝╚══██╔══╝
|
|
8
|
+
██║ █████╗ ██████╔╝██╔████╔██║██║ ██║ ╚███╔╝ █████╗███████╗ ██║ ██║
|
|
9
|
+
██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║██║ ██║ ██╔██╗ ╚════╝╚════██║ ██║ ██║
|
|
10
|
+
██║ ███████╗██║ ██║██║ ╚═╝ ██║╚██████╔╝██╔╝ ██╗ ███████║ ██║ ██║
|
|
11
|
+
╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
**Production-Grade On-Device Speech-to-Text & Speaker Diarization Framework for Android Termux**
|
|
15
|
+
*Dual-Engine Architecture (Python & Node.js / TypeScript) with Native Bionic ARM64 Acceleration & 0 PyTorch Dependency*
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<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>
|
|
19
|
+
<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>
|
|
20
|
+
<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>
|
|
21
|
+
<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>
|
|
22
|
+
<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>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
<img src="https://img.shields.io/badge/Platform-Android%20Termux%20(ARM64%2Faarch64)-00887A?style=flat-square&logo=android&logoColor=white" alt="Platform" />
|
|
27
|
+
<img src="https://img.shields.io/badge/Engines-whisper.cpp%20%7C%20Vosk%20%7C%20Sherpa--ONNX-38bdf8?style=flat-square" alt="Engines" />
|
|
28
|
+
<img src="https://img.shields.io/badge/Diarization-128d%20X--Vector%20+%20Pure%20Python-a855f7?style=flat-square" alt="Diarization" />
|
|
29
|
+
<img src="https://img.shields.io/badge/RAM-Under%20350MB%20(Tiny%2FBase)-10b981?style=flat-square&logo=shield&logoColor=white" alt="RAM" />
|
|
30
|
+
<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" />
|
|
31
|
+
<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" />
|
|
32
|
+
</p>
|
|
33
|
+
|
|
34
|
+
<br/>
|
|
35
|
+
|
|
36
|
+
**[🎧 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)**
|
|
37
|
+
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 🎙️ 단 3줄로 끝내는 안드로이드 Termux 온디바이스 음성인식
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from termux_stt import create_engine
|
|
46
|
+
|
|
47
|
+
# 1. 엔진 초기화 (최초 1회 모델 자동 다운로드 및 캐싱)
|
|
48
|
+
engine = create_engine("whisper", model="base", lang="en")
|
|
49
|
+
|
|
50
|
+
# 2. 오디오 전사 및 자막 생성 (WAV, MP3, M4A, FLAC, OGG 자동 16kHz 변환)
|
|
51
|
+
result = engine.transcribe("speech.mp3")
|
|
52
|
+
|
|
53
|
+
print(result.text) # 전체 텍스트
|
|
54
|
+
print(result.to_srt()) # 표준 SRT 자막
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# 또는 터미널에서 1줄 CLI 실행
|
|
59
|
+
termux-stt transcribe --engine whisper --model base speech.mp3
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 🎧 Live Audio Showcase & On-Device Transcription Proof
|
|
65
|
+
|
|
66
|
+
> **[▶ 웹 브라우저에서 실시간 음성 및 동기화 자막 체험하기 (Live Audio Showcase)](https://uno-km.github.io/termux-stt/showcase.html)**
|
|
67
|
+
|
|
68
|
+
### 1. 실측 오디오 스펙 & 전사 타임라인
|
|
69
|
+
|
|
70
|
+
* **입력 오디오**: `continuous_speech.wav` (37.91초, 16000Hz Mono PCM)
|
|
71
|
+
* **추론 엔진**: `whisper.cpp Base` (On-Device Local CPU)
|
|
72
|
+
* **처리 시간**: **32.79초** (RTF: **0.865x**, 실시간보다 빠름)
|
|
73
|
+
* **문장 반복률**: **0%** (모든 발화 구간이 각기 다른 내용으로 고유하게 전사됨)
|
|
74
|
+
|
|
75
|
+
| No. | 타임스탬프 (시작 → 종료) | 전사된 문장 (Transcribed Text) |
|
|
76
|
+
| :---: | :---: | :--- |
|
|
77
|
+
| **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"* |
|
|
78
|
+
| **02** | `00:09.36 → 00:11.60` | *"do for your country."* |
|
|
79
|
+
| **03** | `00:11.60 → 00:16.18` | *He hoped there would be stew for dinner, turnips and carrots and bruised potatoes and* |
|
|
80
|
+
| **04** | `00:16.18 → 00:22.00` | *fat mutton pieces to be ladled out in thick, peppered flour-fatten sauce.* |
|
|
81
|
+
| **05** | `00:22.00 → 00:25.36` | *Stuff it into you, his belly counseled him.* |
|
|
82
|
+
| **06** | `00:25.36 → 00:29.88` | *After early nightfall, the yellow lamps would light up here and there, the squalid quarter* |
|
|
83
|
+
| **07** | `00:29.88 → 00:37.14` | *of the brothels.* |
|
|
84
|
+
|
|
85
|
+
### 2. 자동 생성된 SRT 자막 파일
|
|
86
|
+
|
|
87
|
+
```srt
|
|
88
|
+
1
|
|
89
|
+
00:00:00,000 --> 00:00:09,360
|
|
90
|
+
"And so my fellow Americans, ask not what your country can do for you, ask what you can
|
|
91
|
+
|
|
92
|
+
2
|
|
93
|
+
00:00:09,360 --> 00:00:11,600
|
|
94
|
+
do for your country."
|
|
95
|
+
|
|
96
|
+
3
|
|
97
|
+
00:00:11,600 --> 00:00:16,180
|
|
98
|
+
He hoped there would be stew for dinner, turnips and carrots and bruised potatoes and
|
|
99
|
+
|
|
100
|
+
4
|
|
101
|
+
00:00:16,180 --> 00:00:22,000
|
|
102
|
+
fat mutton pieces to be ladled out in thick, peppered flour-fatten sauce.
|
|
103
|
+
|
|
104
|
+
5
|
|
105
|
+
00:00:22,000 --> 00:00:25,360
|
|
106
|
+
Stuff it into you, his belly counseled him.
|
|
107
|
+
|
|
108
|
+
6
|
|
109
|
+
00:00:25,360 --> 00:00:29,880
|
|
110
|
+
After early nightfall, the yellow lamps would light up here and there, the squalid quarter
|
|
111
|
+
|
|
112
|
+
7
|
|
113
|
+
00:00:29,880 --> 00:00:37,140
|
|
114
|
+
of the brothels.
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## 💡 What is termux-stt?
|
|
120
|
+
|
|
121
|
+
`termux-stt` is an all-in-one, production-ready speech-to-text and speaker diarization framework engineered natively for **Android Termux (ARM64 / aarch64)**.
|
|
122
|
+
|
|
123
|
+
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.
|
|
124
|
+
|
|
125
|
+
**`termux-stt` eliminates all friction with a 3-line unified API:**
|
|
126
|
+
- **Zero-PyTorch Dependency**: Replaces heavy ML frameworks with C++ binary subprocess isolation and Pure Python clustering math.
|
|
127
|
+
- **Multi-Engine Unification**: Run `whisper.cpp`, `Vosk`, or `Sherpa-ONNX` via the exact same `create_engine()` interface.
|
|
128
|
+
- **Built-in Hybrid Diarization**: Combines Vosk 128d X-Vector voice fingerprints with Whisper STT under 1.5 GB RAM.
|
|
129
|
+
- **Empirically Proven**: Engineered from 15 comprehensive benchmarks on Samsung Galaxy A35 (Exynos 1380, 6GB RAM).
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## 1. Quick Scenario Playbook
|
|
134
|
+
|
|
135
|
+
### [Install] Scenario 1: Clean Install (Fresh Setup on Android Termux)
|
|
136
|
+
|
|
137
|
+
#### [Python] Python (`pip`):
|
|
138
|
+
```bash
|
|
139
|
+
# 1. Grant Storage & Microphone Permissions in Termux
|
|
140
|
+
termux-setup-storage
|
|
141
|
+
|
|
142
|
+
# 2. Install Dependencies & Provision Native Engines
|
|
143
|
+
pkg update -y && pkg install python clang make cmake git ffmpeg termux-api -y
|
|
144
|
+
pip install termux-stt && termux-stt-install
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### [Node.js] Node.js / TypeScript (`npm`):
|
|
148
|
+
```bash
|
|
149
|
+
# 1. Grant Storage & Microphone Permissions
|
|
150
|
+
termux-setup-storage
|
|
151
|
+
|
|
152
|
+
# 2. Install Dependencies & Provision Native Engines
|
|
153
|
+
pkg update -y && pkg install nodejs-lts clang make cmake git ffmpeg termux-api -y
|
|
154
|
+
npm install -g termux-stt && npx termux-stt install
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
### [Instant] Scenario 2: Instant Transcription (Ready to Run)
|
|
160
|
+
|
|
161
|
+
#### Option A: One-Line CLI
|
|
162
|
+
```bash
|
|
163
|
+
# Transcribe audio file with default Whisper engine (Korean)
|
|
164
|
+
termux-stt transcribe meeting.wav
|
|
165
|
+
|
|
166
|
+
# Export directly to Subtitles (SRT or VTT)
|
|
167
|
+
termux-stt transcribe --format srt meeting.wav > subtitles.srt
|
|
168
|
+
|
|
169
|
+
# Use ultra-fast Vosk engine
|
|
170
|
+
termux-stt transcribe --engine vosk --model small-ko voice_memo.wav
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### Option B: Python SDK Integration
|
|
174
|
+
```python
|
|
175
|
+
from termux_stt import create_engine
|
|
176
|
+
|
|
177
|
+
# 1. Initialize Engine (auto-downloads model on first call)
|
|
178
|
+
engine = create_engine("whisper", model="base", lang="ko")
|
|
179
|
+
|
|
180
|
+
# 2. Transcribe Audio
|
|
181
|
+
result = engine.transcribe("meeting.wav")
|
|
182
|
+
|
|
183
|
+
print("Transcript:", result.text)
|
|
184
|
+
print("Detected Language:", result.language)
|
|
185
|
+
print("Duration:", f"{result.duration:.2f}s")
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
#### Option C: Node.js / TypeScript Integration
|
|
189
|
+
```javascript
|
|
190
|
+
const { createEngine } = require("termux-stt");
|
|
191
|
+
|
|
192
|
+
async function main() {
|
|
193
|
+
const engine = createEngine("whisper", { model: "base", lang: "ko" });
|
|
194
|
+
const result = await engine.transcribe("meeting.wav");
|
|
195
|
+
|
|
196
|
+
console.log("Transcript:", result.text);
|
|
197
|
+
console.log("SRT Subtitles:\n", result.toSrt());
|
|
198
|
+
}
|
|
199
|
+
main();
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
### [Streaming] Scenario 3: Real-Time Microphone Streaming
|
|
205
|
+
|
|
206
|
+
Speak into your smartphone microphone and receive real-time transcribed text with sub-second latency:
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
from termux_stt import create_engine
|
|
210
|
+
|
|
211
|
+
# Use ultra-lightweight Tiny model (RTF 0.80 on Exynos 1380)
|
|
212
|
+
engine = create_engine("whisper", model="tiny", lang="ko")
|
|
213
|
+
|
|
214
|
+
print("🎙️ Listening... Speak into your phone microphone (Ctrl+C to stop)")
|
|
215
|
+
for segment in engine.stream_mic():
|
|
216
|
+
print(f"[{segment.start:.1f}s -> {segment.end:.1f}s] {segment.text}")
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
### [Diarize] Scenario 4: Hybrid Speaker Diarization ("Who Spoke When?")
|
|
222
|
+
|
|
223
|
+
Run high-precision speaker diarization without PyTorch or CUDA:
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
from termux_stt import create_engine
|
|
227
|
+
|
|
228
|
+
# Hybrid Pipeline: Vosk 128d X-Vector + Whisper STT + Pure Python K-Means
|
|
229
|
+
engine = create_engine("hybrid", lang="ko", num_speakers=2)
|
|
230
|
+
result = engine.diarize("interview.wav")
|
|
231
|
+
|
|
232
|
+
for seg in result.segments:
|
|
233
|
+
print(f"[{seg.speaker}] ({seg.start:.1f}s - {seg.end:.1f}s): {seg.text}")
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
*Output Example:*
|
|
237
|
+
```text
|
|
238
|
+
[Speaker_0] (0.0s - 3.5s): 오늘 경제 브리핑을 시작하겠습니다.
|
|
239
|
+
[Speaker_1] (3.8s - 7.2s): 네, 오늘 코스피 지수가 외국인 순매수로 상승 마감했습니다.
|
|
240
|
+
[Speaker_0] (7.5s - 10.1s): 반도체 섹터 동향은 어떤가요?
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## 2. 🏛️ Why termux-stt? Architectural Pillars
|
|
246
|
+
|
|
247
|
+
```
|
|
248
|
+
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
249
|
+
│ termux-stt Architecture │
|
|
250
|
+
├────────────────────────┬────────────────────────┬───────────────────────────┤
|
|
251
|
+
│ User Interface Layer │ Engine Abstraction │ Output / Export Layer │
|
|
252
|
+
│ • Python API │ • EngineRegistry │ • JSON / SRT / VTT │
|
|
253
|
+
│ • Node.js API │ • create_engine() │ • RTTM (Diarization) │
|
|
254
|
+
│ • CLI (termux-stt) │ • ModelHub & Cache │ • Streaming Callback │
|
|
255
|
+
├────────────────────────┼────────────────────────┼───────────────────────────┤
|
|
256
|
+
│ Core Pipeline Layer │
|
|
257
|
+
│ Audio Loader (7 Formats) ➔ Preprocessor (16kHz Mono) ➔ Silero-VAD Filter │
|
|
258
|
+
│ ➔ Multi-Engine STT (whisper.cpp / Vosk / Sherpa-ONNX) │
|
|
259
|
+
│ ➔ Hybrid Diarizer (128d X-Vector ➔ Pure Python Cosine/K-Means ➔ Time Align)│
|
|
260
|
+
├─────────────────────────────────────────────────────────────────────────────┤
|
|
261
|
+
│ Platform & Process Isolation │
|
|
262
|
+
│ • Subprocess Isolation (Host Python never crashes on C++ Segfault) │
|
|
263
|
+
│ • MobileGuard (WakeLock, Doze Mode Bypass, Phantom Process Killer Shield) │
|
|
264
|
+
│ • Bionic ARM64 NEON & FP16 SIMD Acceleration │
|
|
265
|
+
└─────────────────────────────────────────────────────────────────────────────┘
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
1. **Subprocess Isolation**: C++ inference runs in isolated native subprocesses. Memory errors or Segfaults never kill the host Python/Node.js application.
|
|
269
|
+
2. **Pure Python Clustering**: Cosine distance matrix and K-Means clustering are implemented with 0 external dependencies (`numpy` / `scikit-learn` optional, not required).
|
|
270
|
+
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.
|
|
271
|
+
4. **Mobile Battery & CPU Guard**: Manages Android WakeLocks and background task states to prevent process termination when the screen locks.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## 3. 📊 Empirical Benchmarks (Galaxy A35 / Exynos 1380)
|
|
276
|
+
|
|
277
|
+
> *Measured on Samsung Galaxy A35 5G (Exynos 1380 4x A78 + 4x A55, 6GB RAM, Android 14 Termux).*
|
|
278
|
+
|
|
279
|
+
| Engine / Pipeline | Model | Peak RAM | RTF (Speed) | KO Accuracy | Diarization Support | Termux Rating |
|
|
280
|
+
| :--- | :--- | :---: | :---: | :---: | :---: | :---: |
|
|
281
|
+
| **whisper.cpp** | `ggml-tiny` (39M) | **~150 MB** | **0.80** | 85% | ❌ External | ⭐⭐⭐⭐⭐ |
|
|
282
|
+
| **whisper.cpp** | `ggml-base` (74M) | ~250 MB | 1.20 | 88% | ❌ External | ⭐⭐⭐⭐ |
|
|
283
|
+
| **whisper.cpp** | `ggml-medium` (769M) | ~1.5 GB | 3.40 | **95%+** | ❌ External | ⭐⭐⭐ (Golden Acc) |
|
|
284
|
+
| **Vosk** | `small-ko-0.22` (42M) | **~100 MB** | **0.25** | 78% | ✅ 128d X-Vector | ⭐⭐⭐ |
|
|
285
|
+
| **Sherpa-ONNX** | `Zipformer` | ~300 MB | **0.42** | 86% | ✅ CAM++ | ⭐⭐⭐⭐ |
|
|
286
|
+
| **Pyannote.audio 3.1** | `diarization-3.1` | **> 3.5 GB** | 2.80~3.50 | N/A | ✅ Gold Standard | ❌ OOM Crashes |
|
|
287
|
+
| **termux-stt (Hybrid)** | `Vosk + Whisper Base`| **~350 MB** | **1.45** | **92%+** | **✅ Built-in K-Means** | **⭐⭐⭐⭐⭐ (Recommended)** |
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## 4. ⚙️ Engine Comparison Matrix
|
|
292
|
+
|
|
293
|
+
| Feature | `whisper.cpp` | `Vosk` | `Sherpa-ONNX` | `Hybrid (Vosk+Whisper)` |
|
|
294
|
+
| :--- | :---: | :---: | :---: | :---: |
|
|
295
|
+
| **Primary Strength** | Highest Text Accuracy | Ultra-Low RAM & Fast | Ultra-Low Latency | **STT + Diarization Combined** |
|
|
296
|
+
| **Memory Footprint** | 150MB ~ 1.5GB | **< 100MB** | 300MB ~ 500MB | **~ 350MB** |
|
|
297
|
+
| **Real-Time Factor (RTF)** | 0.80 (Tiny) | **0.25 (Blazing)** | **0.42 (Fast)** | 1.45 (Full Pipeline) |
|
|
298
|
+
| **Speaker Diarization** | ❌ None | ⚠️ Basic X-Vector | ⚠️ CAM++ C++ | **✅ High-Precision Aligned** |
|
|
299
|
+
| **Recommended Use Case** | Quality Transcripts | Embedded / Low Spec | Live Voice Assistant | **Meetings / Interviews** |
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## 5. 📚 Complete API Reference Summary
|
|
304
|
+
|
|
305
|
+
### Python API
|
|
306
|
+
|
|
307
|
+
```python
|
|
308
|
+
import termux_stt
|
|
309
|
+
|
|
310
|
+
# Create Engine
|
|
311
|
+
engine = termux_stt.create_engine(
|
|
312
|
+
engine="whisper", # "whisper" | "vosk" | "sherpa" | "hybrid"
|
|
313
|
+
model="base", # "tiny" | "base" | "small" | "medium" | "custom"
|
|
314
|
+
lang="ko", # ISO 639-1 language code
|
|
315
|
+
num_speakers=0, # 0 = disabled, 2+ = enable diarization
|
|
316
|
+
threads=4, # CPU threads (defaults to big cores count)
|
|
317
|
+
vad=True, # Enable Silero-VAD silence stripping
|
|
318
|
+
quantization="q5_1" # "f16" | "q8_0" | "q5_1" | "q4_0"
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
# Transcribe File
|
|
322
|
+
result = engine.transcribe("audio.wav")
|
|
323
|
+
# Returns: TranscriptResult(text=str, segments=List[Segment], language=str, duration=float)
|
|
324
|
+
|
|
325
|
+
# Export Methods
|
|
326
|
+
result.to_json() # Structured JSON string
|
|
327
|
+
result.to_srt() # Standard SRT subtitle format
|
|
328
|
+
result.to_vtt() # WebVTT subtitle format
|
|
329
|
+
result.to_rttm() # NIST RTTM diarization format
|
|
330
|
+
|
|
331
|
+
# Stream Microphone
|
|
332
|
+
for seg in engine.stream_mic(duration=30.0):
|
|
333
|
+
print(f"[{seg.speaker}] {seg.text}")
|
|
334
|
+
|
|
335
|
+
# Speaker Diarization
|
|
336
|
+
diar_result = engine.diarize("meeting.wav", num_speakers=2)
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### CLI Reference
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
# General Syntax
|
|
343
|
+
termux-stt [COMMAND] [OPTIONS] [FILE]
|
|
344
|
+
|
|
345
|
+
# Commands
|
|
346
|
+
termux-stt transcribe [FILE] # Transcribe audio file
|
|
347
|
+
termux-stt listen # Real-time microphone transcription
|
|
348
|
+
termux-stt diarize [FILE] # Perform speaker diarization
|
|
349
|
+
termux-stt models list # List installed and available models
|
|
350
|
+
termux-stt models download [M] # Download specific model
|
|
351
|
+
termux-stt doctor # Run hardware and environment diagnostics
|
|
352
|
+
termux-stt benchmark # Run performance benchmark suite
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## 6. 🛠️ Troubleshooting & Android FAQs
|
|
358
|
+
|
|
359
|
+
### Q1: `pip install vosk` fails with CMake or wheel error on Android
|
|
360
|
+
* **Cause**: Vosk does not publish official prebuilt aarch64-android wheels on PyPI.
|
|
361
|
+
* **Solution**: `termux-stt-install` automatically extracts `libvosk.so` from the official Android AAR and generates the CFFI bindings.
|
|
362
|
+
|
|
363
|
+
### Q2: Whisper crashes on 44.1kHz stereo MP3/M4A files
|
|
364
|
+
* **Cause**: Whisper models strictly require single-channel 16,000Hz 16-bit PCM WAV.
|
|
365
|
+
* **Solution**: `termux-stt` automatically runs `ffmpeg` normalization on any audio format (`mp3`, `m4a`, `flac`, `ogg`, `opus`, `webm`).
|
|
366
|
+
|
|
367
|
+
### Q3: Process killed after 10 minutes in background
|
|
368
|
+
* **Cause**: Android Phantom Process Killer terminates background tasks.
|
|
369
|
+
* **Solution**: Enable Termux WakeLock (`termux-wake-lock`) and disable battery optimization for Termux in Android Settings.
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## 7. 🔍 15-Part Empirical Research Blog Series
|
|
374
|
+
|
|
375
|
+
This framework is built upon the exhaustive 15-part research series published on [Eunho Kim's Technical Blog (우노킴 티스토리)](https://uno-kim.tistory.com/):
|
|
376
|
+
|
|
377
|
+
1. [[Whisper.cpp] #1. Edge Agent AI: Whisper.cpp Speech Processing (Base vs Tiny)](https://uno-kim.tistory.com/467)
|
|
378
|
+
2. [[Audio Extraction] #2. Extracting Specific Audio Segments on Android](https://uno-kim.tistory.com/468)
|
|
379
|
+
3. [[Whisper.cpp] #3. Korean STT Conversion Comparison (4 Models)](https://uno-kim.tistory.com/469)
|
|
380
|
+
4. [[Comparison-1] #4. STT + Speaker Diarization: 3 Lightweight Engines + Pyannote](https://uno-kim.tistory.com/472)
|
|
381
|
+
5. [[Comparison-2] #5. Sherpa-ONNX Execution, Diarization, and Troubleshooting](https://uno-kim.tistory.com/473)
|
|
382
|
+
6. [[Comparison-3] #6. Speaker Diarization using Pyannote Model](https://uno-kim.tistory.com/471)
|
|
383
|
+
7. [[Pyannote] Troubleshooting Diarization in Mobile/Termux/ARM Environments](https://uno-kim.tistory.com/470)
|
|
384
|
+
8. [[Comparison-4] #7. Vosk Execution, Speaker Diarization, and Troubleshooting](https://uno-kim.tistory.com/475)
|
|
385
|
+
9. [[Vosk] Troubleshooting Vosk in Mobile/Termux/ARM Environments](https://uno-kim.tistory.com/474)
|
|
386
|
+
10. [[Comparison-5] #8. Vosk / Pyannote / Sherpa-ONNX / Whisper.cpp Comprehensive Comparison](https://uno-kim.tistory.com/476)
|
|
387
|
+
11. [[Comparison-6] #9. Vosk + Whisper.cpp Hybrid Pipeline & X-Vector Diarization](https://uno-kim.tistory.com/477)
|
|
388
|
+
12. [[Development-1] #10. Large-Scale Batch Automation & Task Management Architecture](https://uno-kim.tistory.com/478)
|
|
389
|
+
13. [[Comparison-7] #11. STT + Diarization Final: Small vs Turbo & Optimization Magic (4-Model Benchmark)](https://uno-kim.tistory.com/479)
|
|
390
|
+
14. [[Development-2] #12. Domain-Specific STT Training: Whisper Tiny Fine-Tuning on CPU](https://uno-kim.tistory.com/480)
|
|
391
|
+
15. [[Comparison-8] #13. Vanilla Model vs Custom Fine-Tuned Model (Economics/News Domain)](https://uno-kim.tistory.com/481)
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## 🌌 The AMEVA Mobile AI & Automation Ecosystem
|
|
396
|
+
|
|
397
|
+
* **🎨 [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.
|
|
398
|
+
* **🌐 [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.
|
|
399
|
+
* **🧠 [termux-train](https://github.com/uno-km/termux-train)**: On-device Autograd deep learning training & LoRA fine-tuning for Android Termux.
|
|
400
|
+
* **🖥️ [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.
|
|
401
|
+
* **⚡ [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.
|
|
402
|
+
|
|
403
|
+
---
|
|
404
|
+
|
|
405
|
+
## ⚖️ Disclaimer (면책 조항)
|
|
406
|
+
|
|
407
|
+
> **Disclaimer:**
|
|
408
|
+
> *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.*
|
|
409
|
+
>
|
|
410
|
+
> *(본 프로젝트는 안드로이드 Termux 환경을 위해 개발된 독립적인 오픈소스 라이브러리이며, Termux 공식 프로젝트, OpenAI 및 기타 제3자와 직접적인 제휴 관계가 아닙니다.)*
|
|
411
|
+
|
|
412
|
+
---
|
|
413
|
+
|
|
414
|
+
## 📄 License
|
|
415
|
+
|
|
416
|
+
Released under the **MIT License**. Maintained by **uno-km (쌩초보코딩단) / Eunho Kim**.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* termux-stt CLI for Node.js / npx
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { spawn } = require('child_process');
|
|
8
|
+
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
|
|
11
|
+
// Forward to Python CLI
|
|
12
|
+
const pythonArgs = ['-m', 'termux_stt.cli.main', ...args];
|
|
13
|
+
const proc = spawn('python', pythonArgs, {
|
|
14
|
+
stdio: 'inherit',
|
|
15
|
+
env: process.env
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
proc.on('close', (code) => {
|
|
19
|
+
process.exit(code || 0);
|
|
20
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export interface EngineOptions {
|
|
2
|
+
model?: string;
|
|
3
|
+
lang?: string;
|
|
4
|
+
threads?: number;
|
|
5
|
+
vad?: boolean;
|
|
6
|
+
vadThreshold?: number;
|
|
7
|
+
quantization?: string;
|
|
8
|
+
numSpeakers?: number;
|
|
9
|
+
customModelPath?: string;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Segment {
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
text: string;
|
|
17
|
+
speaker?: string;
|
|
18
|
+
confidence?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class TranscriptResult {
|
|
22
|
+
text: string;
|
|
23
|
+
segments: Segment[];
|
|
24
|
+
language?: string;
|
|
25
|
+
duration?: number;
|
|
26
|
+
speakers?: string[];
|
|
27
|
+
|
|
28
|
+
toJson(): string;
|
|
29
|
+
toSrt(): string;
|
|
30
|
+
toVtt(): string;
|
|
31
|
+
toRttm(fileId?: string): string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export abstract class Engine {
|
|
35
|
+
options: EngineOptions;
|
|
36
|
+
constructor(options?: EngineOptions);
|
|
37
|
+
abstract transcribe(audioPath: string, options?: any): Promise<TranscriptResult>;
|
|
38
|
+
abstract diarize(audioPath: string, numSpeakers?: number): Promise<TranscriptResult>;
|
|
39
|
+
getInfo(): Record<string, any>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class WhisperEngine extends Engine {
|
|
43
|
+
transcribe(audioPath: string, options?: any): Promise<TranscriptResult>;
|
|
44
|
+
diarize(audioPath: string, numSpeakers?: number): Promise<TranscriptResult>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class VoskEngine extends Engine {
|
|
48
|
+
transcribe(audioPath: string, options?: any): Promise<TranscriptResult>;
|
|
49
|
+
diarize(audioPath: string, numSpeakers?: number): Promise<TranscriptResult>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class HybridEngine extends Engine {
|
|
53
|
+
transcribe(audioPath: string, options?: any): Promise<TranscriptResult>;
|
|
54
|
+
diarize(audioPath: string, numSpeakers?: number): Promise<TranscriptResult>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createEngine(
|
|
58
|
+
engineName?: 'whisper' | 'vosk' | 'hybrid' | string,
|
|
59
|
+
options?: EngineOptions
|
|
60
|
+
): Engine;
|
|
61
|
+
|
|
62
|
+
export function formatTime(seconds: number, separator?: string): string;
|
package/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* termux-stt Node.js entry point
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { Engine, TranscriptResult, Segment, formatTime } = require('./lib/engine');
|
|
6
|
+
const { WhisperEngine } = require('./lib/whisper');
|
|
7
|
+
const { VoskEngine } = require('./lib/vosk');
|
|
8
|
+
const { HybridEngine } = require('./lib/hybrid');
|
|
9
|
+
|
|
10
|
+
function createEngine(engineName = 'whisper', options = {}) {
|
|
11
|
+
const name = String(engineName).toLowerCase();
|
|
12
|
+
switch (name) {
|
|
13
|
+
case 'whisper':
|
|
14
|
+
return new WhisperEngine(options);
|
|
15
|
+
case 'vosk':
|
|
16
|
+
return new VoskEngine(options);
|
|
17
|
+
case 'hybrid':
|
|
18
|
+
return new HybridEngine(options);
|
|
19
|
+
default:
|
|
20
|
+
throw new Error(`Unknown engine: ${engineName}. Available: whisper, vosk, hybrid`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = {
|
|
25
|
+
createEngine,
|
|
26
|
+
Engine,
|
|
27
|
+
TranscriptResult,
|
|
28
|
+
Segment,
|
|
29
|
+
WhisperEngine,
|
|
30
|
+
VoskEngine,
|
|
31
|
+
HybridEngine,
|
|
32
|
+
formatTime
|
|
33
|
+
};
|
package/lib/engine.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* termux-stt - Engine Abstraction for Node.js
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
class TranscriptResult {
|
|
6
|
+
constructor(text, segments = [], language = 'ko', duration = 0) {
|
|
7
|
+
this.text = text;
|
|
8
|
+
this.segments = segments;
|
|
9
|
+
this.language = language;
|
|
10
|
+
this.duration = duration;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
toJson() {
|
|
14
|
+
return JSON.stringify(this, null, 2);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
toSrt() {
|
|
18
|
+
return this.segments.map((seg, i) => {
|
|
19
|
+
const start = formatTime(seg.start);
|
|
20
|
+
const end = formatTime(seg.end);
|
|
21
|
+
return `${i + 1}\n${start} --> ${end}\n${seg.text}\n`;
|
|
22
|
+
}).join('\n');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toVtt() {
|
|
26
|
+
const body = this.segments.map((seg) => {
|
|
27
|
+
const start = formatTime(seg.start, true);
|
|
28
|
+
const end = formatTime(seg.end, true);
|
|
29
|
+
return `${start} --> ${end}\n${seg.text}\n`;
|
|
30
|
+
}).join('\n');
|
|
31
|
+
return `WEBVTT\n\n${body}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
toRttm(fileId = 'audio') {
|
|
35
|
+
return this.segments.map((seg) => {
|
|
36
|
+
const spk = seg.speaker || 'Speaker_0';
|
|
37
|
+
const dur = (seg.end - seg.start).toFixed(2);
|
|
38
|
+
return `SPEAKER ${fileId} 1 ${seg.start.toFixed(2)} ${dur} <NA> <NA> ${spk} <NA> <NA>`;
|
|
39
|
+
}).join('\n');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class Segment {
|
|
44
|
+
constructor(start, end, text, speaker = null, confidence = null) {
|
|
45
|
+
this.start = start;
|
|
46
|
+
this.end = end;
|
|
47
|
+
this.text = text;
|
|
48
|
+
this.speaker = speaker;
|
|
49
|
+
this.confidence = confidence;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function formatTime(seconds, isVtt = false) {
|
|
54
|
+
const s = Math.max(0, seconds || 0);
|
|
55
|
+
const hrs = Math.floor(s / 3600);
|
|
56
|
+
const mins = Math.floor((s % 3600) / 60);
|
|
57
|
+
const secs = Math.floor(s % 60);
|
|
58
|
+
const ms = Math.floor((s % 1) * 1000);
|
|
59
|
+
|
|
60
|
+
const pad = (n, z = 2) => String(n).padStart(z, '0');
|
|
61
|
+
const sep = isVtt ? '.' : ',';
|
|
62
|
+
return `${pad(hrs)}:${pad(mins)}:${pad(secs)}${sep}${pad(ms, 3)}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class Engine {
|
|
66
|
+
constructor(config = {}) {
|
|
67
|
+
this.config = config;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async transcribe(audioPath, options = {}) {
|
|
71
|
+
throw new Error('transcribe() must be implemented by subclass');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async diarize(audioPath, numSpeakers = 2) {
|
|
75
|
+
throw new Error('diarize() must be implemented by subclass');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
streamMic(duration = null) {
|
|
79
|
+
throw new Error('streamMic() must be implemented by subclass');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getInfo() {
|
|
83
|
+
return { name: this.constructor.name, config: this.config };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = {
|
|
88
|
+
Engine,
|
|
89
|
+
TranscriptResult,
|
|
90
|
+
Segment,
|
|
91
|
+
formatTime
|
|
92
|
+
};
|
package/lib/hybrid.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HybridEngine for Node.js - Vosk X-Vector Diarization + Whisper STT
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { spawn } = require('child_process');
|
|
6
|
+
const { Engine, TranscriptResult, Segment } = require('./engine');
|
|
7
|
+
|
|
8
|
+
class HybridEngine extends Engine {
|
|
9
|
+
constructor(config = {}) {
|
|
10
|
+
super(config);
|
|
11
|
+
this.model = config.model || 'base';
|
|
12
|
+
this.lang = config.lang || 'ko';
|
|
13
|
+
this.numSpeakers = config.numSpeakers || 2;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async transcribe(audioPath, options = {}) {
|
|
17
|
+
return this.diarize(audioPath, this.numSpeakers);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async diarize(audioPath, numSpeakers = 2) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const args = [
|
|
23
|
+
'-m', 'termux_stt.cli.main',
|
|
24
|
+
'diarize',
|
|
25
|
+
'--speakers', String(numSpeakers),
|
|
26
|
+
'--format', 'json',
|
|
27
|
+
audioPath
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const proc = spawn('python', args, { env: process.env });
|
|
31
|
+
let stdout = '';
|
|
32
|
+
let stderr = '';
|
|
33
|
+
|
|
34
|
+
proc.stdout.on('data', (d) => { stdout += d.toString(); });
|
|
35
|
+
proc.stderr.on('data', (d) => { stderr += d.toString(); });
|
|
36
|
+
|
|
37
|
+
proc.on('close', (code) => {
|
|
38
|
+
if (code !== 0) {
|
|
39
|
+
return reject(new Error(`Hybrid diarization failed (code ${code}): ${stderr}`));
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(stdout);
|
|
43
|
+
const segments = (parsed.segments || []).map(
|
|
44
|
+
s => new Segment(s.start, s.end, s.text, s.speaker, s.confidence)
|
|
45
|
+
);
|
|
46
|
+
resolve(new TranscriptResult(parsed.text, segments, parsed.language || this.lang, parsed.duration));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
resolve(new TranscriptResult(stdout.trim(), [new Segment(0, 0, stdout.trim())], this.lang));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getInfo() {
|
|
55
|
+
return {
|
|
56
|
+
name: 'Hybrid Vosk+Whisper (Node.js)',
|
|
57
|
+
model: this.model,
|
|
58
|
+
language: this.lang,
|
|
59
|
+
numSpeakers: this.numSpeakers
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { HybridEngine };
|
package/lib/vosk.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VoskEngine for Node.js
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { spawn } = require('child_process');
|
|
6
|
+
const { Engine, TranscriptResult, Segment } = require('./engine');
|
|
7
|
+
|
|
8
|
+
class VoskEngine extends Engine {
|
|
9
|
+
constructor(config = {}) {
|
|
10
|
+
super(config);
|
|
11
|
+
this.model = config.model || 'small-ko-0.22';
|
|
12
|
+
this.lang = config.lang || 'ko';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async transcribe(audioPath, options = {}) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const args = [
|
|
18
|
+
'-m', 'termux_stt.cli.main',
|
|
19
|
+
'transcribe',
|
|
20
|
+
'--engine', 'vosk',
|
|
21
|
+
'--model', this.model,
|
|
22
|
+
'--lang', this.lang,
|
|
23
|
+
'--format', 'json',
|
|
24
|
+
audioPath
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const proc = spawn('python', args, { env: process.env });
|
|
28
|
+
let stdout = '';
|
|
29
|
+
let stderr = '';
|
|
30
|
+
|
|
31
|
+
proc.stdout.on('data', (d) => { stdout += d.toString(); });
|
|
32
|
+
proc.stderr.on('data', (d) => { stderr += d.toString(); });
|
|
33
|
+
|
|
34
|
+
proc.on('close', (code) => {
|
|
35
|
+
if (code !== 0) {
|
|
36
|
+
return reject(new Error(`Vosk transcription failed (code ${code}): ${stderr}`));
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const parsed = JSON.parse(stdout);
|
|
40
|
+
const segments = (parsed.segments || []).map(
|
|
41
|
+
s => new Segment(s.start, s.end, s.text, s.speaker, s.confidence)
|
|
42
|
+
);
|
|
43
|
+
resolve(new TranscriptResult(parsed.text, segments, parsed.language || this.lang, parsed.duration));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
resolve(new TranscriptResult(stdout.trim(), [new Segment(0, 0, stdout.trim())], this.lang));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getInfo() {
|
|
52
|
+
return {
|
|
53
|
+
name: 'Vosk (Node.js)',
|
|
54
|
+
model: this.model,
|
|
55
|
+
language: this.lang
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = { VoskEngine };
|
package/lib/whisper.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WhisperEngine for Node.js - wraps whisper.cpp via spawn or termux-stt CLI
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { spawn } = require('child_process');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { Engine, TranscriptResult, Segment } = require('./engine');
|
|
9
|
+
|
|
10
|
+
class WhisperEngine extends Engine {
|
|
11
|
+
constructor(config = {}) {
|
|
12
|
+
super(config);
|
|
13
|
+
this.model = config.model || 'base';
|
|
14
|
+
this.lang = config.lang || 'ko';
|
|
15
|
+
this.threads = config.threads || 4;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async transcribe(audioPath, options = {}) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
// Use termux-stt python CLI or direct whisper.cpp
|
|
21
|
+
const args = [
|
|
22
|
+
'-m', 'termux_stt.cli.main',
|
|
23
|
+
'transcribe',
|
|
24
|
+
'--engine', 'whisper',
|
|
25
|
+
'--model', this.model,
|
|
26
|
+
'--lang', this.lang,
|
|
27
|
+
'--format', 'json',
|
|
28
|
+
audioPath
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const proc = spawn('python', args, { env: process.env });
|
|
32
|
+
let stdout = '';
|
|
33
|
+
let stderr = '';
|
|
34
|
+
|
|
35
|
+
proc.stdout.on('data', (d) => { stdout += d.toString(); });
|
|
36
|
+
proc.stderr.on('data', (d) => { stderr += d.toString(); });
|
|
37
|
+
|
|
38
|
+
proc.on('close', (code) => {
|
|
39
|
+
if (code !== 0) {
|
|
40
|
+
return reject(new Error(`whisper transcription failed (code ${code}): ${stderr}`));
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(stdout);
|
|
44
|
+
const segments = (parsed.segments || []).map(
|
|
45
|
+
s => new Segment(s.start, s.end, s.text, s.speaker, s.confidence)
|
|
46
|
+
);
|
|
47
|
+
resolve(new TranscriptResult(parsed.text, segments, parsed.language || this.lang, parsed.duration));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
// Fallback if stdout was plain text
|
|
50
|
+
resolve(new TranscriptResult(stdout.trim(), [new Segment(0, 0, stdout.trim())], this.lang));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getInfo() {
|
|
57
|
+
return {
|
|
58
|
+
name: 'whisper.cpp (Node.js)',
|
|
59
|
+
model: this.model,
|
|
60
|
+
language: this.lang,
|
|
61
|
+
threads: this.threads
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = { WhisperEngine };
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "termux-stt",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Production-Grade On-Device Speech-to-Text & Speaker Diarization Framework for Android Termux & Samsung Galaxy",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"termux-stt": "./bin/termux-stt.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.js",
|
|
12
|
+
"index.d.ts",
|
|
13
|
+
"lib",
|
|
14
|
+
"bin",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/uno-km/termux-stt.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"termux",
|
|
24
|
+
"stt",
|
|
25
|
+
"speech-to-text",
|
|
26
|
+
"whisper",
|
|
27
|
+
"whisper-cpp",
|
|
28
|
+
"vosk",
|
|
29
|
+
"sherpa-onnx",
|
|
30
|
+
"diarization",
|
|
31
|
+
"speaker-diarization",
|
|
32
|
+
"android",
|
|
33
|
+
"samsung-galaxy",
|
|
34
|
+
"edge-ai",
|
|
35
|
+
"on-device-ai",
|
|
36
|
+
"pure-python",
|
|
37
|
+
"exynos",
|
|
38
|
+
"snapdragon",
|
|
39
|
+
"arm64"
|
|
40
|
+
],
|
|
41
|
+
"author": "uno-km (쌩초보코딩단) <hosequelbo@gmail.com>",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/uno-km/termux-stt/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://uno-km.github.io/termux-stt/",
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=16.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|