Overview
TheSpeechToText class provides an async interface to the Unmute STT server via WebSocket. It streams audio data and receives real-time transcription along with Voice Activity Detection (VAD) pause predictions.
Class Definition
Constructor
str
default:"STT_SERVER"
URL of the STT server instance
float
default:"STT_DELAY_SEC"
Processing delay in seconds for the STT pipeline
Properties
pause_prediction
attack_time: 0.01 secondsrelease_time: 0.01 secondsinitial_value: 1.0
sent_samples
current_time
received_words
Core Methods
send_audio
np.ndarray
required
1D numpy array of audio samples (float32 format)
ValueError: If audio is not a 1D array
- Automatically converts audio to float32 if needed
- Updates
sent_samplescounter - Increments metrics for monitoring
send_marker
int
required
Unique marker identifier
start_up
MissingServiceAtCapacity: If STT server is at capacityRuntimeError: If unexpected message type received during startup
shutdown
- Session duration
- Total audio duration
- Number of words transcribed
state
Literal["not_created", "connecting", "connected", "closing", "closed"]
Async Iterator
aiter
STTWordMessage: Transcribed word with timing informationSTTMarkerMessage: Synchronization marker
Message Types
STTWordMessage
STTMarkerMessage
STTStepMessage
STTErrorMessage
STTReadyMessage
Example Usage
Advanced Usage: Pause Detection
Metrics
The class automatically tracks the following metrics:STT_ACTIVE_SESSIONS: Active transcription sessionsSTT_SENT_FRAMES: Audio frames sent to serverSTT_RECV_FRAMES: Processing steps receivedSTT_RECV_WORDS: Words transcribedSTT_TTFT: Time to first token (transcription)STT_SESSION_DURATION: Total session durationSTT_AUDIO_DURATION: Total audio processedSTT_NUM_WORDS: Total words per session
Notes
- Audio is expected at 24kHz sample rate
- The STT pipeline has an inherent delay (configurable via
delay_sec) - Pause predictions are smoothed using exponential moving average
- First 12 processing steps are ignored for pause prediction to avoid initial noise
- Connection is automatically closed when iteration completes