termux-stt Logo

termux-stt

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

100% Full API Reference

Exhaustive specification for all public functions, classes, and types.

Factory Function: create_engine()

def create_engine(
    engine: str = "whisper",
    *,
    model: Optional[str] = None,
    lang: str = "ko",
    num_speakers: int = 0,
    threads: Optional[int] = None,
    vad: bool = True,
    vad_threshold: float = 0.5,
    quantization: str = "q5_1",
    custom_model_path: Optional[str] = None,
    **kwargs
) -> Engine

Class: Engine (Abstract Base Class)

Data Classes: TranscriptResult & Segment

@dataclass
class Segment:
    start: float           # Start time in seconds
    end: float             # End time in seconds
    text: str              # Transcribed text
    speaker: Optional[str] = None      # e.g. "Speaker_0"
    confidence: Optional[float] = None # 0.0 - 1.0

@dataclass
class TranscriptResult:
    text: str
    segments: List[Segment]
    language: Optional[str] = None
    duration: Optional[float] = None

    def to_json(self) -> str: ...
    def to_srt(self) -> str: ...
    def to_vtt(self) -> str: ...
    def to_rttm(self, file_id: str = "audio") -> str: ...

@dataclass
class DiarizedResult(TranscriptResult):
    speakers: List[str] = field(default_factory=list)

Clustering: KMeans & cosine_similarity

# Pure Python Math - Zero ML dependencies
from termux_stt.diarization.clustering import KMeans, cosine_similarity, euclidean_distance

sim = cosine_similarity(vec_a, vec_b)
kmeans = KMeans(n_clusters=2, seed=42)
kmeans.fit(vectors_128d)
labels = kmeans.predict(vectors_128d)