Recognizing speech... Info: Error opening streams - read error=1

Clinical Avatar 0 Reputation points
2025-02-28T04:54:58.6133333+00:00

I have this code to call the Speech recognition and it always fails with opening streams error. I tried both ways - audio stream and wav file. neither is working.

def recognize_speech_from_base64(base64_audio: str,languagecode):
    """
    Decodes the base64-encoded audio and performs speech recognition using Azure.
    """
    try:
        # Decode base64 to raw bytes
        audio_bytes = decode_base64_audio(base64_audio)
        if audio_bytes is None:
            return {"status": "error", "message": "Invalid Base64 input"}

        # Save audio as WAV file
        wav_filename = "/Users/raj/Downloads/Sports_fixed.wav" #convert_webm_to_wav(audio_bytes)
        if wav_filename is None:
            return {"status": "error", "message": "Failed to save audio file"}
        
        # Initialize Azure Speech SDK
        speech_config = speechsdk.SpeechConfig(subscription=AZURE_SPEECH_KEY, region=AZURE_REGION)
        speech_config.speech_recognition_language = languagecode

        # Use file-based AudioConfig
        audio_config = speechsdk.audio.AudioConfig(filename=f"{wav_filename}")

        # Create a speech recognizer
        speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)

        print(f"Processing file: {wav_filename}")
        print("Recognizing speech...")

        result = speech_recognizer.recognize_once()  # Perform recognition

        # Clean up the temporary file
        # os.remove(wav_filename)

        # Check recognition result
        if result.reason == speechsdk.ResultReason.RecognizedSpeech:
            print("Recognized Text:", result.text)
            return {"status": "success", "transcription": result.text}
        elif result.reason == speechsdk.ResultReason.NoMatch:
            print("No speech recognized.")
            return {"status": "error", "message": "No speech recognized."}
        elif result.reason == speechsdk.ResultReason.Canceled:
            cancellation_details = result.cancellation_details
            print(f"Speech recognition canceled: {cancellation_details.reason}")
            return {"status": "error", "message": f"Canceled: {cancellation_details.reason}"}
    except Exception as e:
        print(f"Error in speech recognition: {e}")
        return {"status": "error", "message": str(e)}

Error:
Recognizing speech...

Info: Error opening streams - read error=1

Error: Time:Fri Feb 28 15:10:20 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_close_async Line:383 NULL on_io_close_complete

Error: Time:Fri Feb 28 15:10:20 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/src/uws_client.c Func:on_underlying_io_open_complete Line:751 underlying on_io_open_complete was called again after upgrade request was sent.

Error: Time:Fri Feb 28 15:10:20 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_close_async Line:383 NULL on_io_close_complete

Error: Time:Fri Feb 28 15:10:20 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: Error opening streams - read error=1

Error: Time:Fri Feb 28 15:10:20 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_close_async Line:383 NULL on_io_close_complete

Error: Time:Fri Feb 28 15:10:20 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/src/uws_client.c Func:on_underlying_io_open_complete Line:751 underlying on_io_open_complete was called again after upgrade request was sent.

Error: Time:Fri Feb 28 15:10:20 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_close_async Line:383 NULL on_io_close_complete

Error: Time:Fri Feb 28 15:10:20 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: Error opening streams - read error=1

Error: Time:Fri Feb 28 15:10:20 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_close_async Line:383 NULL on_io_close_complete

Error: Time:Fri Feb 28 15:10:20 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/src/uws_client.c Func:on_underlying_io_open_complete Line:751 underlying on_io_open_complete was called again after upgrade request was sent.

Error: Time:Fri Feb 28 15:10:20 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_close_async Line:383 NULL on_io_close_complete

Error: Time:Fri Feb 28 15:10:20 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: Error opening streams - read error=1

Error: Time:Fri Feb 28 15:10:20 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_close_async Line:383 NULL on_io_close_complete

Error: Time:Fri Feb 28 15:10:21 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/src/uws_client.c Func:on_underlying_io_open_complete Line:751 underlying on_io_open_complete was called again after upgrade request was sent.

Error: Time:Fri Feb 28 15:10:21 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_close_async Line:383 NULL on_io_close_complete

Error: Time:Fri Feb 28 15:10:21 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: Error opening streams - read error=1

Error: Time:Fri Feb 28 15:10:21 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_close_async Line:383 NULL on_io_close_complete

Error: Time:Fri Feb 28 15:10:21 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/src/uws_client.c Func:on_underlying_io_open_complete Line:751 underlying on_io_open_complete was called again after upgrade request was sent.

Error: Time:Fri Feb 28 15:10:21 2025 File:/Users/runner/work/1/s/external/azure-c-shared-utility/pal/ios-osx/tlsio_appleios.c Func:tlsio_appleios_close_async Line:383 NULL on_io_close_complete

Speech recognition canceled: CancellationReason.Error

Error: Time:Fri Feb 28 15:10:22 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.

Response : {'status': 'error', 'message': 'Canceled: CancellationReason.Error'}

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,927 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Burlachenko 1,665 Reputation points
    2025-02-28T08:51:40.58+00:00

    Hi Clinical Avatar, quickly review urs issue, so in this case, I would do the following: :::)))
    check the file path and access permissions.

    convert the file to the required format (PCM WAV 16kHz, 16bit, Mono).

    verify the API key and region in Azure.

    update the Azure Speech SDK (pip install --upgrade azure-cognitiveservices-speech).

    run the code using a VPN or a different Azure region.

    add debugging before calling speechsdk.SpeechRecognizer to check the parameters.

    If the issue persists, try running the code on a different operating system or using another library for audio processing.

    rgds,

    Alex

    Please click Accept Answer and upvote if the above was helpful.

    0 comments No comments

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.