package com.sherpaonnxofflinestt /** * Centralized configuration constants for STT module. * All magic numbers and default values should be defined here. * * NOTE: This file is mirrored in iOS (ios/STTConstants.swift). * Any changes here MUST be mirrored in iOS to maintain platform parity. * Both files should have identical values and equivalent constant names. */ object STTConstants { // ===================== // Audio Processing // ===================== /** Default sample rate in Hz */ const val DEFAULT_SAMPLE_RATE = 16000 /** VAD frame size in samples (10ms at 16kHz) */ const val VAD_HOP_SIZE = 160 /** Maximum denoiser chunk size in samples (5 seconds at 16kHz) */ const val MAX_DENOISER_CHUNK_SAMPLES = 5 * DEFAULT_SAMPLE_RATE /** Chunk size for audio recording in milliseconds */ const val AUDIO_CHUNK_SIZE_MS = 80 /** Minimum peak amplitude to process STT (avoid noise hallucinations) */ const val MIN_PEAK_FOR_STT = 0.01f /** Target peak amplitude for audio normalization */ const val TARGET_PEAK_AMPLITUDE = 0.9f // ===================== // VAD Defaults // ===================== /** Default VAD speech probability threshold */ const val DEFAULT_VAD_THRESHOLD = 0.5f /** Minimum speech duration in milliseconds to trigger recognition */ const val DEFAULT_MIN_SPEECH_MS = 300 /** Minimum silence duration in milliseconds to end speech segment */ const val DEFAULT_MIN_SILENCE_MS = 500 /** Maximum speech duration in milliseconds before forced segment break */ const val DEFAULT_MAX_SPEECH_MS = 30000 /** Padding around speech segments in milliseconds */ const val DEFAULT_SPEECH_PADDING_MS = 100 /** Threshold adjustment for aggressive VAD mode */ const val VAD_MODE_AGGRESSIVE_ADJUSTMENT = 0.15f /** Threshold adjustment for sensitive VAD mode */ const val VAD_MODE_SENSITIVE_ADJUSTMENT = -0.15f /** Maximum VAD threshold allowed */ const val VAD_THRESHOLD_MAX = 0.9f /** Minimum VAD threshold allowed */ const val VAD_THRESHOLD_MIN = 0.1f // ===================== // Diarization Defaults // ===================== /** Default speaker similarity threshold for assignment (lenient) */ const val DEFAULT_SPEAKER_THRESHOLD = 0.55f /** Default embedding similarity threshold for profile update (strict) */ const val DEFAULT_EMBEDDING_THRESHOLD = 0.70f /** Maximum number of tracked speakers (LRU eviction) */ const val DEFAULT_MAX_SPEAKERS = 10 /** Minimum speech duration for speaker creation in milliseconds */ const val DEFAULT_MIN_SPEECH_DURATION_MS = 800 /** Minimum speech duration for embedding update in milliseconds */ const val DEFAULT_MIN_EMBEDDING_UPDATE_MS = 500 /** Weight for running average embedding update */ const val DEFAULT_EMBEDDING_AVERAGE_WEIGHT = 0.2f /** Number of onboarding segments for first speaker stabilization */ const val DEFAULT_ONBOARDING_SEGMENTS = 3 /** Minimum accumulated speech before creating new speaker in milliseconds */ const val DEFAULT_MIN_SPEECH_FOR_NEW_SPEAKER = 3000 /** Diarization window size for sub-segment processing in milliseconds */ const val DIARIZATION_WINDOW_SIZE_MS = 1500 /** Diarization window step (50% overlap) in milliseconds */ const val DIARIZATION_WINDOW_STEP_MS = 750 // ===================== // Streaming State // ===================== /** Default confidence threshold for confirming volatile text */ const val DEFAULT_CONFIRMATION_THRESHOLD = 0.85f /** Minimum audio context in milliseconds before confirmation */ const val DEFAULT_MIN_CONTEXT_MS = 5000L // ===================== // Embedding Validation // ===================== /** Minimum embedding norm for valid embedding */ const val MIN_EMBEDDING_NORM = 0.001f /** Quality normalization factor for embedding variance */ const val EMBEDDING_QUALITY_FACTOR = 10f // ===================== // Pyannote Defaults // ===================== /** Default clustering threshold for auto speaker detection */ const val DEFAULT_CLUSTERING_THRESHOLD = 0.5f /** Default minimum duration for speech segment in seconds */ const val DEFAULT_MIN_DURATION_ON = 0.5f /** Default minimum duration for silence segment in seconds */ const val DEFAULT_MIN_DURATION_OFF = 0.3f // ===================== // Streaming Endpoint Detection // ===================== /** Rule 1: Minimum trailing silence in seconds (longer pause detection) */ const val DEFAULT_RULE1_MIN_TRAILING_SILENCE = 2.4f /** Rule 2: Minimum trailing silence in seconds (shorter pause detection) */ const val DEFAULT_RULE2_MIN_TRAILING_SILENCE = 1.2f /** Rule 3: Minimum utterance length in seconds before endpoint */ const val DEFAULT_RULE3_MIN_UTTERANCE_LENGTH = 20.0f // ===================== // Model Inference // ===================== /** Default number of threads for STT inference */ const val DEFAULT_STT_NUM_THREADS = 4 /** Default number of threads for embedding/denoiser inference */ const val DEFAULT_AUXILIARY_NUM_THREADS = 2 /** Default ONNX runtime provider */ const val DEFAULT_PROVIDER = "cpu" }