Strange Error with Azure Speech Service TTS, suddenly stopped working

Enrique Alcazar 0 Reputation points
2025-05-05T14:38:54.37+00:00

I have a voice agent built with Livekit that uses Azure Speech Service TTS, but last week I suddenly started getting this error when running my agent.

I'm not sure what the error is since there is no error code and the error message shown in the first couple of lines is not very clear. I tried looking at the logs in my service but there was no clear error there either. How can I find out why this is happening and stop it?

Error: Time:Wed Apr 30 15:06:25 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_destroy Line:196 tlsio_appleios_destroy called while not in TLSIO_STATE_CLOSED.
Info: on_underlying_io_close_sent: uws_client=0x12c8d61e0, io_send_result:2
Info: on_underlying_io_close_sent: closing underlying io.
Info: on_underlying_io_close_complete: uws_state: 6.
2025-04-30 15:06:25,098 - WARNING livekit.agents - failed to recognize speech, retrying in 0.1s
Traceback (most recent call last):
  File "/Users/lara/Documents/omniloy/voice_assistant/.venv/lib/python3.13/site-packages/livekit/agents/stt/stt.py", line 228, in _main_task
    return await self._run()
           ^^^^^^^^^^^^^^^^^
  File "/Users/lara/Documents/omniloy/voice_assistant/.venv/lib/python3.13/site-packages/livekit/plugins/azure/stt.py", line 225, in _run
    raise APIConnectionError("SpeechRecognition session stopped")
livekit.agents._exceptions.APIConnectionError: SpeechRecognition session stopped {"tts": "livekit.plugins.azure.stt.STT", "attempt": 0, "streamed": true, "pid": 98338, "job_id": "AJ_iM3s8K4Vuwoy"}
Error: Time:Wed Apr 30 15:06:25 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_destroy Line:196 tlsio_appleios_destroy called while not in TLSIO_STATE_CLOSED.
2025-04-30 15:06:25,201 - WARNING livekit.agents - failed to recognize speech, retrying in 2.0s
Traceback (most recent call last):
  File "/Users/lara/Documents/omniloy/voice_assistant/.venv/lib/python3.13/site-packages/livekit/agents/stt/stt.py", line 228, in _main_task
    return await self._run()
           ^^^^^^^^^^^^^^^^^
  File "/Users/lara/Documents/omniloy/voice_assistant/.venv/lib/python3.13/site-packages/livekit/plugins/azure/stt.py", line 225, in _run
    raise APIConnectionError("SpeechRecognition session stopped")
Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
2,001 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Prashanth Veeragoni 4,360 Reputation points Microsoft External Staff Moderator
    2025-05-06T01:47:40.5933333+00:00

    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!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.