speechmatics return error {"message": "failed to ...
# ask-ai
b
speechmatics return error {"message": "failed to recognize speech, retrying in 0.1s\nTraceback (most recent call last):\n File \"/Users/junxie/Projects/chatot/venv/lib/python3.13/site-packages/livekit/agents/stt/stt.py\", line 251, in _main_task\n return await self._run()\n ^^^^^^^^^^^^^^^^^\n File \"/Users/junxie/Projects/chatot/venv/lib/python3.13/site-packages/livekit/plugins/speechmatics/stt.py\", line 231, in _run\n task.result()\n ~~~~~~~~~~~^^\n File \"/Users/junxie/Projects/chatot/venv/lib/python3.13/site-packages/livekit/plugins/speechmatics/stt.py\", line 204, in recv_task\n raise APIStatusError(message=\"Speechmatics connection closed unexpectedly\")\nlivekit.agents._exceptions.APIStatusError: Speechmatics connection closed unexpectedly (status_code=-1, request_id=None, body=None, retryable=True)", "level": "WARNING", "name": "livekit.agents", "tts": "livekit.plugins.speechmatics.stt.STT", "attempt": 0, "streamed": true, "pid": 22645, "job_id": "AJ_mqUtqzLVJ5G6", "timestamp": "2025-10-11T050928.110101+00:00"}
t
Thanks for reaching out, Ethan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like the error is telling us that the Speechmatics connection was unexpectedly closed. Don’t worry, let’s work through some steps together to get this sorted out: 1. Verify Authentication: Please double-check that your Speechmatics API key is correctly set in the environment variable
SPEECHMATICS_API_KEY
. This is often a simple fix! 2. Check Base URL: Make sure the Speechmatics real-time URL is accessible and correctly set in
SPEECHMATICS_RT_URL
. The default should be
wss://eu2.rt.speechmatics.com/v2
, so it’s good to confirm this. 3. Monitor Connection Lifecycle: Take a look at your logs to see if there are any patterns or clues around WebSocket connection issues or unexpected closures. 4. Run Diagnostics: It’s helpful to test WebSocket, WebRTC, and TURN server connectivity to rule out any wider network problems that might be affecting things. If you’re still seeing the issue after trying these, could you please share a bit more info with me? For example: • Does the error happen right when you try to connect, or does it come up during use? • Have you confirmed the API key and URL settings are correct? • Are you using a firewall or VPN that might be interfering with WebSocket connections? I’m here to help, so feel free to share whatever you can, and we’ll get this resolved together! Sources: Diagnosing Connection Errors with Connection Test Utility | agents/src/worker.ts | livekit-plugins/livekit-plugins-speechmatics/livekit/plugins/speechmatics/s...
b
Does the error happen right when you try to connect => Yes Have you confirmed the API key and URL settings are correct => yes Are you using a firewall or VPN that might be interfering with WebSocket connections => No firewall. The connection works 30 minutes ago, but now the API doesn't work
t
It’s great that the connection was working earlier, and I understand how frustrating it can be when it suddenly stops. Let’s work through some steps together to get to the bottom of this: 1. Enable Debug Logging: Turning on detailed logging for Speechmatics can give us more clues about what’s going wrong. You can add this snippet to your setup to capture more info:
Copy code
import logging
logging.getLogger("speechmatics.rt.transport").setLevel(logging.DEBUG)
1. Verify API Key Permissions: Let’s double-check that your Speechmatics API key has all the permissions needed for real-time transcription. 2. Test WebSocket Connectivity: Try using a WebSocket client to connect to
wss://eu2.rt.speechmatics.com/v2
outside of LiveKit. This can help us see if there might be any network hiccups. 3. Check for Configuration Changes: Have there been any recent changes to your Speechmatics account or API key settings? It’s good to confirm nothing has been updated unintentionally. Also, if you could take a look at the logs when the connection fails and share any specific error messages you see, that would be super helpful. We’re here to figure this out together! Sources: examples/voice_agents/speaker_id_multi_speaker.py
b
how to 1. Test WebSocket Connectivity: Try using a WebSocket client to connect to
wss://eu2.rt.speechmatics.com/v2
outside of LiveKit. This can help us see if there might be any network hiccups.
t
To help you test the WebSocket connectivity to
wss://eu2.rt.speechmatics.com/v2
, here are a few friendly options you can try: 1. Using a WebSocket Testing Tool: You might find it easy to use an online tool like PieSocket WebSocket Tester or a similar service. Just enter the URL
wss://eu2.rt.speechmatics.com/v2
and give connecting a go. 2. Using a Command-Line Tool: If you’re comfortable with the command line, you can install a WebSocket client like
wscat
(which is Node.js-based): `npm install -g wscat`Then, you can test the connection by running:
wscat -c wss://eu2.rt.speechmatics.com/v2
3. Using Python: Prefer Python? No problem! You can use the
websockets
library like this:
Copy code
import asyncio
import websockets

async def test_connection():
    async with websockets.connect("wss://eu2.rt.speechmatics.com/v2") as websocket:
        print("Connection successful")

asyncio.run(test_connection())
Please feel free to reach out if you run into any hiccups during these tests or just want to share that it worked smoothly. I’m here to help!
b
Copy code
- Connecting to: wss://eu2.rt.speechmatics.com/v2?jwt=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzbWlzc3VlciIsImF1ZCI6WyJldSIsImV1LTEiXSwiZXhwIjoxNzYwMTYwNTIzLCJuYmYiOjE3NjAxNTY4NjMsImlhdCI6MTc2MDE2MDQ2MywiY29udHJhY3RfaWQiOiIxOTMyMTMiLCJwcm9qZWN0X2lkIjoiMTkzODA1IiwicHJvZHVjdCI6InJ0IiwidXNlcl9pZCI6InNlbGZzZXJ2aWNlLTE5MzIxNCIsImFjY291bnRfdHlwZSI6InBhaWQiLCJjb25uZWN0aW9uX3F1b3RhIjoiNTAifQ.GHA8nmIfMHq_A0ja5cdBdx4nO1zDU7voTv4iRaGrvOGMF_7ey6TfJ_M40OIVCIWh1GD3bnaZ3lmxUzF77CAF3gz03PUGy9rwLwplUWxKEBaEvd7nZK5mEkhZWpLAwr_d5-IDCbJeajXDTVUmR9XDFI5YzjGC-MqOPbsGQdiy-_MMCkzpOY9Os2ZCHMPca--_hSJUj-lv5Ax5LTNfBsJRjAaBt0-si6TwgEO8hgnZ2BVdAuXVK1oKIajEvVhsnDO9AECEMOdBp_AYFB7w2yS6hKuoJiRpIUskFaFgGIegX63H84MnJAB8AshuCvzBghunc5K3kZNcRIxjbsGooxfIKFGZb3V57kUI-sR9pkL73bHvAX43grda8K0zfUW8U0TT3fyfXBXgURluTaAc1RIqcwdDDgP2SbAiUtXaBKDy86MVSlxBRbf8vgN2VLXw2VMaOH09Kzubk0HeoDiU3sbT93thpsKj2KInxKSCzxXxRMtobu8ITEP1XHCwXICUNGS-
- Connection Established
▼ {"message":"Info","type":"concurrent_session_usage","reason":"1 concurrent sessions active out of quota 50","usage":1,"quota":50,"last_updated":"2025-10-11T05:28:00Z"}
t
Great news! The WebSocket connection to Speechmatics was successfully established, and the response shows that 1 concurrent session is active out of a quota of 50. This means your API key and connection settings are working just as they should. Since the connection works outside of LiveKit, it seems like the hiccup might be with how LiveKit is handling the Speechmatics integration. Here are a few friendly next steps to try: 1. Check LiveKit Logs: Take a look at the LiveKit logs for any errors or warnings related to the Speechmatics plugin. Sometimes the logs can give us valuable clues. 2. Verify Audio Format: Double-check that the audio format settings in LiveKit match what Speechmatics needs (like sample rate and encoding). 3. Restart LiveKit Services: If things are still acting up, giving the LiveKit services a quick restart can help reset the connection. Please don’t hesitate to reach out if you’d like a hand with any of these steps or if the issue keeps popping up after trying them. I’m here to help!