# Speechmatics Real-Time API Client
[](https://pypi.org/project/speechmatics-rt/)

Async Python client for the Speechmatics Real-Time API.
## Features
- **Async-first design** with simpler interface
- **Multi-channel transcription** - Simultaneous processing of multiple audio sources
- **Single-stream transcription** - Optimized client for single audio source
- **Comprehensive error handling** with detailed error messages
- **Type hints throughout** for excellent IDE support and code safety
- **Environment variable support** for secure credential management
- **Event-driven architecture** for real-time transcript processing
- **Simple connection management** with clear error reporting
## Installation
```bash
pip install speechmatics-rt
```
## Quick Start
```python
import asyncio
from speechmatics.rt import AsyncClient, ServerMessageType
async def main():
# Create a client using environment variable SPEECHMATICS_API_KEY
async with AsyncClient() as client:
# Register event handlers
@client.on(ServerMessageType.ADD_TRANSCRIPT)
def handle_final_transcript(msg):
print(f"Final: {msg['metadata']['transcript']}")
# Transcribe audio file
with open("audio.wav", "rb") as audio_file:
await client.transcribe(audio_file)
# Run the async function
asyncio.run(main())
```
### Multi-Channel Transcription
```python
import asyncio
from speechmatics.rt import AsyncMultiChannelClient, ServerMessageType, TranscriptionConfig
async def main():
# Prepare multiple audio sources
sources = {
"left": open("left.wav", "rb"),
"right": open("right.wav", "rb"),
}
try:
async with AsyncMultiChannelClient() as client:
# Handle transcripts with channel identification
@client.on(ServerMessageType.ADD_TRANSCRIPT)
def handle_transcript(msg):
channel = msg["results"][0]["channel"]
transcript = msg["metadata"]["transcript"]
print(f"[{channel}]: {transcript}")
# Start multi-channel transcription
await client.transcribe(
sources,
transcription_config=TranscriptionConfig(
language="en",
diarization="channel",
channel_diarization_labels=list(sources.keys()),
)
)
finally:
# Ensure all files are closed
for source in sources.values():
source.close()
asyncio.run(main())
```
## JWT Authentication
For enhanced security, use temporary JWT tokens instead of static API keys.
JWTs are short-lived (60 seconds by default).
```python
from speechmatics.rt import AsyncClient, JWTAuth
# Create JWT auth (requires: pip install 'speechmatics-rt[jwt]')
auth = JWTAuth("your-api-key", ttl=60)
async with AsyncClient(auth=auth) as client:
pass
```
Ideal for browser applications or when minimizing API key exposure.
See the [authentication documentation](https://docs.speechmatics.com/introduction/authentication) for more details.
## Logging
The client supports logging with job id tracing for debugging.
To increase logging verbosity, set `DEBUG` level in your example code:
```python
import logging
import sys
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler(sys.stdout)
]
)
```
### Environment Variables
The client supports the following environment variables:
- `SPEECHMATICS_API_KEY`: Your Speechmatics API key
- `SPEECHMATICS_RT_URL`: Custom API endpoint URL (optional)
Raw data
{
"_id": null,
"home_page": null,
"name": "speechmatics-rt",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "speechmatics, speech-to-text, real-time, transcription, websocket",
"author": null,
"author_email": "Speechmatics <support@speechmatics.com>",
"download_url": "https://files.pythonhosted.org/packages/e7/e2/c9f5776af66ea424782131f17747f754d2a11cce2116e78f2dbe95d481dc/speechmatics_rt-0.4.1.tar.gz",
"platform": null,
"description": "# Speechmatics Real-Time API Client\n\n[](https://pypi.org/project/speechmatics-rt/)\n\n\nAsync Python client for the Speechmatics Real-Time API.\n\n## Features\n\n- **Async-first design** with simpler interface\n- **Multi-channel transcription** - Simultaneous processing of multiple audio sources\n- **Single-stream transcription** - Optimized client for single audio source\n- **Comprehensive error handling** with detailed error messages\n- **Type hints throughout** for excellent IDE support and code safety\n- **Environment variable support** for secure credential management\n- **Event-driven architecture** for real-time transcript processing\n- **Simple connection management** with clear error reporting\n\n## Installation\n\n```bash\npip install speechmatics-rt\n\n```\n## Quick Start\n\n```python\nimport asyncio\nfrom speechmatics.rt import AsyncClient, ServerMessageType\n\n\nasync def main():\n # Create a client using environment variable SPEECHMATICS_API_KEY\n async with AsyncClient() as client:\n # Register event handlers\n @client.on(ServerMessageType.ADD_TRANSCRIPT)\n def handle_final_transcript(msg):\n print(f\"Final: {msg['metadata']['transcript']}\")\n\n # Transcribe audio file\n with open(\"audio.wav\", \"rb\") as audio_file:\n await client.transcribe(audio_file)\n\n# Run the async function\nasyncio.run(main())\n```\n\n### Multi-Channel Transcription\n\n```python\nimport asyncio\nfrom speechmatics.rt import AsyncMultiChannelClient, ServerMessageType, TranscriptionConfig\n\nasync def main():\n # Prepare multiple audio sources\n sources = {\n \"left\": open(\"left.wav\", \"rb\"),\n \"right\": open(\"right.wav\", \"rb\"),\n }\n\n try:\n async with AsyncMultiChannelClient() as client:\n # Handle transcripts with channel identification\n @client.on(ServerMessageType.ADD_TRANSCRIPT)\n def handle_transcript(msg):\n channel = msg[\"results\"][0][\"channel\"]\n transcript = msg[\"metadata\"][\"transcript\"]\n print(f\"[{channel}]: {transcript}\")\n\n # Start multi-channel transcription\n await client.transcribe(\n sources,\n transcription_config=TranscriptionConfig(\n language=\"en\",\n diarization=\"channel\",\n channel_diarization_labels=list(sources.keys()),\n )\n )\n finally:\n # Ensure all files are closed\n for source in sources.values():\n source.close()\n\nasyncio.run(main())\n```\n\n## JWT Authentication\n\nFor enhanced security, use temporary JWT tokens instead of static API keys.\nJWTs are short-lived (60 seconds by default).\n\n```python\nfrom speechmatics.rt import AsyncClient, JWTAuth\n\n# Create JWT auth (requires: pip install 'speechmatics-rt[jwt]')\nauth = JWTAuth(\"your-api-key\", ttl=60)\n\nasync with AsyncClient(auth=auth) as client:\n pass\n```\n\nIdeal for browser applications or when minimizing API key exposure.\nSee the [authentication documentation](https://docs.speechmatics.com/introduction/authentication) for more details.\n\n## Logging\n\nThe client supports logging with job id tracing for debugging.\nTo increase logging verbosity, set `DEBUG` level in your example code:\n\n```python\nimport logging\nimport sys\n\nlogging.basicConfig(\n level=logging.DEBUG,\n format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',\n handlers=[\n logging.StreamHandler(sys.stdout)\n ]\n)\n```\n\n### Environment Variables\n\nThe client supports the following environment variables:\n\n- `SPEECHMATICS_API_KEY`: Your Speechmatics API key\n- `SPEECHMATICS_RT_URL`: Custom API endpoint URL (optional)\n",
"bugtrack_url": null,
"license": null,
"summary": "Speechmatics Real-Time API Client",
"version": "0.4.1",
"project_urls": {
"documentation": "https://docs.speechmatics.com/",
"homepage": "https://github.com/speechmatics/speechmatics-python-sdk",
"issues": "https://github.com/speechmatics/speechmatics-python-sdk/issues",
"repository": "https://github.com/speechmatics/speechmatics-python-sdk"
},
"split_keywords": [
"speechmatics",
" speech-to-text",
" real-time",
" transcription",
" websocket"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "570c1a3aae9ef0ca762651ffe872ee91decd04e5ccb804b1d9296773a6c39c74",
"md5": "a98f364ad69a76b09a083baa517ac2f1",
"sha256": "95d56dcc9870ec281d767a39c044baf412626d13fcf100609f1bdb3633ff9b10"
},
"downloads": -1,
"filename": "speechmatics_rt-0.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a98f364ad69a76b09a083baa517ac2f1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 32128,
"upload_time": "2025-08-19T15:20:40",
"upload_time_iso_8601": "2025-08-19T15:20:40.902412Z",
"url": "https://files.pythonhosted.org/packages/57/0c/1a3aae9ef0ca762651ffe872ee91decd04e5ccb804b1d9296773a6c39c74/speechmatics_rt-0.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "e7e2c9f5776af66ea424782131f17747f754d2a11cce2116e78f2dbe95d481dc",
"md5": "8714de365f9ab210d84d37f17660dff9",
"sha256": "12a6119f0dc73bb3ce59afcb3e8c4cc8ccfa47bd77eaec0bce28993c8d925fe2"
},
"downloads": -1,
"filename": "speechmatics_rt-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "8714de365f9ab210d84d37f17660dff9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 26159,
"upload_time": "2025-08-19T15:20:42",
"upload_time_iso_8601": "2025-08-19T15:20:42.042372Z",
"url": "https://files.pythonhosted.org/packages/e7/e2/c9f5776af66ea424782131f17747f754d2a11cce2116e78f2dbe95d481dc/speechmatics_rt-0.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-19 15:20:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "speechmatics",
"github_project": "speechmatics-python-sdk",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "speechmatics-rt"
}