Azure Speech to Text Error Code

Eslam Lotfy 5 Reputation points
2024-02-07T17:25:11.7066667+00:00

error

Exception has occurred: RuntimeError

  • Exception with error code: [CALL STACK BEGIN] > pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - pal_string_to_wstring - recognizer_create_speech_recognizer_from_config [CALL STACK END] Exception with an error code: 0x8 (SPXERR_FILE_OPEN_FAILED)

code

def speech_recognize_continuous_from_file():
    """performs continuous speech recognition with input from an audio file"""
    # <SpeechContinuousRecognitionWithFile>
    speech_config = speechsdk.SpeechConfig(subscription='', region='')
    audio_config = speechsdk.audio.AudioConfig(filename=audiosourcefile)

    speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)

    done = False

    def stop_cb(evt: speechsdk.SessionEventArgs):
        """callback that signals to stop continuous recognition upon receiving an event `evt`"""
        print('CLOSING on {}'.format(evt))
        nonlocal done
        done = True

    # Connect callbacks to the events fired by the speech recognizer
    speech_recognizer.recognizing.connect(lambda evt: print('RECOGNIZING: {}'.format(evt)))
    speech_recognizer.recognized.connect(lambda evt: print('RECOGNIZED: {}'.format(evt)))
    speech_recognizer.session_started.connect(lambda evt: print('SESSION STARTED: {}'.format(evt)))
    speech_recognizer.session_stopped.connect(lambda evt: print('SESSION STOPPED {}'.format(evt)))
    speech_recognizer.canceled.connect(lambda evt: print('CANCELED {}'.format(evt)))
    # Stop continuous recognition on either session stopped or canceled events
    speech_recognizer.session_stopped.connect(stop_cb)
    speech_recognizer.canceled.connect(stop_cb)

    # Start continuous speech recognition
    speech_recognizer.start_continuous_recognition()
    while not done:
        time.sleep(.5)

    speech_recognizer.stop_continuous_recognition()
    # </SpeechContinuousRecognitionWithFile>


speech_recognize_continuous_from_file()
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,944 questions
{count} vote

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 53,236 Reputation points
    2024-02-07T21:04:34.42+00:00

    Thanks for reaching out to us, could you please share the document you are referring to for your code sample ? Did you leverage the whole code sample? If not could you please share the whole sample you are working on so that we can reproduce the error?

    The error code SPXERR_FILE_OPEN_FAILED typically indicates that the Azure Speech Service SDK was unable to open the file you specified in your translation_once_from_file method. This could be due to several reasons:

    1. File does not exist: Check if the file path is correct and the file exists at the specified location.
    2. Incorrect file permissions: The application might not have the necessary permissions to access the file. Ensure that the file permissions allow your application to read the file.
    3. File is being used by another process: If the file is open or being used by another process, the SDK might not be able to access it. Make sure the file is not being used by another process when you run your code.
    4. Unsupported file format: The Azure Speech Service SDK supports certain audio file formats. Make sure your file is in a supported format.

    If you've checked all of these potential issues and you're still encountering the error, it might be helpful to share more details about your code and the specific file you're trying to use.

    Please let us know if you are still blocked by this issue, we can collaborate with support team to see what happened. , I hope this helps.

    Regards,

    Yutong

    1 person found this answer helpful.

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.