Speechmatics Real-Time API Client
raw JSON → 1.0.0 verified Mon Apr 27 auth: no python
Official Python client for Speechmatics real-time speech-to-text API. Version 1.0.0, supports Python >=3.9. Actively maintained.
pip install speechmatics-rt Common errors
error ModuleNotFoundError: No module named 'speechmatics' ↓
cause Wrong import path; the package installs as `speechmatics_rt` not `speechmatics`.
fix
Install the correct package:
pip install speechmatics-rt then import as from speechmatics_rt import WebsocketsClient. error AttributeError: module 'speechmatics_rt' has no attribute 'WebsocketsClient' ↓
cause Forgetting to import the class from the module.
fix
Import correctly:
from speechmatics_rt import WebsocketsClient. error RuntimeError: Connection closed with status 401 ↓
cause Invalid or missing API key.
fix
Set SM_API_KEY environment variable or pass a valid API key to WebsocketsClient.
Warnings
gotcha The library uses underscore in its Python module name: `speechmatics_rt`, not `speechmatics-rt`. ↓
fix Use `from speechmatics_rt import WebsocketsClient`.
gotcha The `run` method is blocking; for non-blocking use `run_async`. ↓
fix Call `client.run_async(audiostream, conf)` instead of `client.run(audiostream, conf)` for async operation.
breaking Version 1.0.0 removed support for Python <3.9. ↓
fix Upgrade to Python 3.9 or later.
Imports
- WebsocketsClient
from speechmatics_rt import WebsocketsClient
Quickstart
from speechmatics_rt import WebsocketsClient
import os
# Obtain an API key from Speechmatics
api_key = os.environ.get('SM_API_KEY', '')
client = WebsocketsClient(api_key)
# Define transcription configuration
conf = {
"type": "transcription",
"transcription_config": {
"language": "en",
"operating_point": "enhanced"
}
}
# Open a connection and send audio file
def on_transcription(message):
print(message)
client.add_listener('transcription', on_transcription)
with open('audio.wav', 'rb') as audio:
client.run(audiostream, conf)