Hi Enrique Alcazar,
Thanks for detailed explanation. this issue seems to involve a low-level TLS (Transport Layer Security) connection issue with Azure Speech Service over WebSockets, possibly due to:
· A disrupted or dropped TLS connection
· An Azure TTS service outage or endpoint change
· Authentication token expiry
· Incorrect SDK cleanup on iOS/macOS (relevant from the tlsio_appleios.c trace)
· A LiveKit or SDK update regression
Let’s troubleshoot this step by step:
1.Verify Azure Speech Service Connectivity
Ensure the endpoint you're calling (region-specific like eastus.api.cognitive.microsoft.com) is still active and reachable.
Run this test from your machine:
curl -v https://<your-region>.tts.speech.microsoft.com/cognitiveservices/v1
You should get a 401 Unauthorized response — that confirms the endpoint is alive.
2.Check Authentication (Key or Token)
If you use subscription keys or Azure Active Directory tokens, verify:
· They haven’t expired or been rotated.
· You're passing the Ocp-Apim-Subscription-Key header correctly.
Also, try regenerating the key and testing again.
3.TLS Connection State Issue (from the logs)
This part of the error:
tlsio_appleios_destroy called while not in TLSIO_STATE_CLOSED.
suggests that the WebSocket/TLS connection wasn’t properly closed before being destroyed. This is common if:
· The process or coroutine is abruptly terminated.
· The SDK version has a bug.
Solution:
· Update the Azure SDKs (especially for Python and iOS/macOS native dependencies)
· Gracefully close the Speech SDK session before destroying objects
4.Retry Backoff/Handling in LiveKit
You're seeing repeated retries:
failed to recognize speech, retrying in 2.0s
If this happens immediately and continuously, it’s likely due to:
· Session timeout issues
· A missing heartbeat
· Improper streaming format or sample rate
Make sure:
· You're sending PCM audio in 16-bit 16kHz mono (if using audio streaming)
· You’re not exceeding the 10-minute session limit (Azure cuts off long streams)
5.Test with Minimal Sample Code
Try running the official TTS sample from Azure here: Text to speech quickstart
Run it outside LiveKit to isolate whether the issue is:
· With your Azure account/config
· With LiveKit integration
6.Upgrade All SDKs
Ensure the following:
· Azure Speech SDK is up to date (pip install azure-cognitiveservices-speech --upgrade)
· LiveKit SDK is also current (pip show livekit)
Hope this helps. Do let us know if you any further queries.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful. And, if you have any further query do let us know.
Thank you!