Speechmatics Agent STT SDK
Python client for the Speechmatics Agent STT service, built on
speechmatics-rt.
The Agent STT service works in segments rather than word groups, and reports the speech and turn events a voice agent needs. This SDK runs no VAD and no turn detection of its own - either the service's VAD closes turns, or your application's does.
pip install speechmatics-agent-stt
Quick start
import asyncio
from speechmatics.agent_stt import AgentSttAsyncClient, ServerMessageType, TranscriptionConfig
async def main():
# Uses SPEECHMATICS_API_KEY from the environment
client = AgentSttAsyncClient(
transcription_config=TranscriptionConfig(language="en", enable_partials=True)
)
# Register handlers before opening the session, so no message can arrive unhandled
@client.on(ServerMessageType.ADD_SEGMENT)
def handle_segment(message):
print(message["segment"]["transcript"])
async with client:
while chunk := next_audio_chunk():
await client.send_audio(chunk)
print(client.transcript)
asyncio.run(main())
Who closes the turn
The service needs a boundary to close a segment on. Pick where it comes from:
from speechmatics.agent_stt import TurnConfig, TurnDetectionMode
# The service's VAD (default). It emits SpeechStarted/SpeechEnded and StartOfTurn/EndOfTurn.
turn_config = TurnConfig(turn_detection_mode=TurnDetectionMode.VAD)
# Your endpointing - Pipecat, LiveKit, or your own. The service's VAD stays off.
turn_config = TurnConfig(turn_detection_mode=TurnDetectionMode.EXTERNAL)
client = AgentSttAsyncClient(
transcription_config=TranscriptionConfig(language="en"), turn_config=turn_config
)
With TurnDetectionMode.EXTERNAL, close each turn when your side decides speech has ended:
client.finalize() # from a sync callback
await client.force_end_of_utterance() # from async code
Either sends ForceEndOfUtterance stamped with the audio position at the moment of the call, so
the service cuts the turn where you heard the end of speech rather than wherever the send lands.
The flushed segment comes back as a normal AddSegment.
What decides that is entirely yours - a VAD, an ML turn model, or a push-to-talk button. The SDK
only cares that something calls finalize().
Session output
Every server message is dispatched to your handlers and also kept on the client:
client.transcript # final segments joined by the language's word delimiter
client.segments # list[Segment] - transcript, timing, speaker, is_final
client.partial_segment # the segment currently in flight, or None
client.timeline # list[TimedEvent] - the speech and turn events, in order
client.events # every raw message, including ones this SDK does not model
client.session_info # session id and the language pack the service reported
client.transcript_text(speaker_labels=True, include_partial=False)
Pass record_events=False to AgentSttAsyncClient for long-running sessions where the raw log is not
wanted.
Messages
Emitted by the service:
| Message | Payload |
|---|---|
AddSegment |
segment.transcript, optional segment.speaker, metadata.start_time, metadata.end_time |
AddPartialSegment |
interim preview of the segment being built |
SpeechStarted / SpeechEnded |
metadata.start_time / metadata.end_time (service VAD) |
StartOfTurn / EndOfTurn |
metadata.start_time / metadata.end_time (service turn detection) |
Passed through from the RT engine: RecognitionStarted, AudioAdded, EndOfTranscript,
SpeakersResult, Info, Warning, Error.
Anything else the engine sends - the word-level AddTranscript/AddPartialTranscript, audio
events - is not modelled here, but still reaches client.events and any handler registered
under its name.
Configuration
TranscriptionConfig is the RT transcription config with the service's own model names.
Turn taking is configured separately, and is fixed for the life of the session:
| Config | Field | Meaning |
|---|---|---|
TurnConfig |
turn_detection_mode |
TurnDetectionMode.VAD (default) or TurnDetectionMode.EXTERNAL |
model takes an Agent STT Model and defaults to DEFAULT_MODEL (Model.LINDEN_1):
from speechmatics.agent_stt import Model, TranscriptionConfig
transcription_config = TranscriptionConfig(model=Model.LINDEN_1)
The proxy in front of the service resolves the Agent STT model name onto the engine's operating
point, so the transcriber never sees a name it has no notion of. The RT models (enhanced,
standard) are not Agent STT models and are not accepted here; the deprecated operating_point
still passes through, and suppresses the model default so the two never arrive together.
Engine silence-based end of utterance is not offered here. A turn ends either because the
service's VAD said so, or because you called finalize().
Endpoint
The Agent STT endpoint is the RT endpoint plus /agent:
AgentSttAsyncClient(url="wss://eu2.rt.speechmatics.com/v2") # -> /v2/agent
AgentSttAsyncClient(url="ws://localhost:8000/v2") # -> /v2/agent
AgentSttAsyncClient(app="pipecat/1.0") # reported as sm-app
Resolution order: the url argument, SPEECHMATICS_RT_URL, then the EU endpoint. The /agent
segment is appended when it is missing.
Audio
The service requires 16 kHz raw PCM, pcm_s16le or pcm_f32le, which is what the client
defaults to. Audio sent before the session is ready, or after it closes, is dropped rather than
raising, so an audio callback does not have to track session state.
Examples
See examples/agent_stt.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file speechmatics_agent_stt-0.1.0.tar.gz.
File metadata
- Download URL: speechmatics_agent_stt-0.1.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca17027d43aab73df16ce757600027f107b07de60aa2434274a0fe0bc0889452
|
|
| MD5 |
fea2955b420d8109c7ecf534128b84ec
|
|
| BLAKE2b-256 |
b552fdc366b34c77aef07b5af89e764c2a40457f125bbcba9df825cfad24bb56
|
File details
Details for the file speechmatics_agent_stt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: speechmatics_agent_stt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e87e1a954660515763834ff268b509a0025cd5484aef092e13a047621d11d5b
|
|
| MD5 |
554fbacd1657d1490ea0171aca97cd74
|
|
| BLAKE2b-256 |
230b71650f93c1328a6a96313b26c60830c9903d01177f8821aaec4b8c45d097
|