Speechmatics Agent STT Python client for agent transcription
Actively maintained. Last release 6 weeks ago, commits in 14 of the last 26 weeks. A safe choice.
pip install speechmatics-agent-sttSpeechmatics 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: