termux-stt Logo

termux-stt

v1.0.0 (Unified STT)
PyPI (pip) npm (Node.js) 💖 Sponsor GitHub

Quickstart & Recipes

Production-ready code snippets for common audio transcription workflows.

Recipe 1: Simple File Transcription

from termux_stt import create_engine

# Initialize Whisper engine
engine = create_engine("whisper", model="base", lang="ko")

# Transcribe any audio file (wav, mp3, m4a, flac, ogg, webm)
result = engine.transcribe("speech.m4a")

print("Text:", result.text)
print("Language:", result.language)
print("Duration:", result.duration)

Recipe 2: Realtime Microphone Streaming

from termux_stt import create_engine

engine = create_engine("whisper", model="tiny", lang="ko")

print("Speak into your device microphone (Ctrl+C to stop)...")
for segment in engine.stream_mic(duration=30.0):
    print(f"[{segment.start:.1f}s - {segment.end:.1f}s] {segment.text}")

Recipe 3: Speaker Diarization (Meeting Minutes)

from termux_stt import create_engine

# Hybrid engine automatically clusters 128d X-Vectors
engine = create_engine("hybrid", lang="ko", num_speakers=2)
result = engine.diarize("meeting_recording.wav")

for seg in result.segments:
    print(f"[{seg.speaker}] ({seg.start:.1f}s-{seg.end:.1f}s): {seg.text}")

# Export to Subtitle / RTTM formats
with open("meeting.srt", "w", encoding="utf-8") as f:
    f.write(result.to_srt())

with open("meeting.rttm", "w", encoding="utf-8") as f:
    f.write(result.to_rttm())

Recipe 4: Batch Processing Directory

import os
from pathlib import Path
from termux_stt import create_engine

engine = create_engine("whisper", model="base", lang="ko")
audio_dir = Path("./recordings")

for file_path in audio_dir.glob("*.wav"):
    print(f"Processing {file_path.name}...")
    res = engine.transcribe(str(file_path))
    txt_path = file_path.with_suffix(".txt")
    txt_path.write_text(res.text, encoding="utf-8")
print("Batch processing complete!")