Azure Real time speech to text not working through python but curl is working

Ulhas Hulyal, Nilesh 0 Reputation points
2025-01-27T09:45:32.9566667+00:00

We have enabled Azure speech to text service with private end point, when we try to use below curl command it we able to get output

curl -i --location 'https://xxxxxxxxxxx?language=en-US' --header 'Accept: application/json' --header 'Ocp-Apim-Subscription-Key: xxxxxxxxx' --header 'Content-Type: audio/wav' --data-binary '@/app/temp/longer_audio.wav'

but when used attached script it is event is getting cancelled, can anyone please help here

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

Accepted answer
  1. kothapally Snigdha 1,100 Reputation points Microsoft Vendor
    2025-01-27T17:45:19.2866667+00:00

    Hi Ulhas Hulyal, Nilesh

    we are able reproduce the issue and able to solve in our environment can you please check once with

    import time
    import azure.cognitiveservices.speech as speechsdk
     
    def conversation_transcriber_recognition_canceled_cb(evt: speechsdk.SessionEventArgs):
        print('Canceled event')
     
    def conversation_transcriber_session_stopped_cb(evt: speechsdk.SessionEventArgs):
        print('SessionStopped event')
     
    def conversation_transcriber_transcribed_cb(evt: speechsdk.SpeechRecognitionEventArgs):
        print('\nTRANSCRIBED:')
        if evt.result.reason == speechsdk.ResultReason.RecognizedSpeech:
            print('\tText={}'.format(evt.result.text))
            print('\tSpeaker ID={}\n'.format(evt.result.speaker_id))
        elif evt.result.reason == speechsdk.ResultReason.NoMatch:
            print('\tNOMATCH: Speech could not be TRANSCRIBED: {}'.format(evt.result.no_match_details))
     
    def conversation_transcriber_transcribing_cb(evt: speechsdk.SpeechRecognitionEventArgs):
        print('TRANSCRIBING:')
        print('\tText={}'.format(evt.result.text))
        print('\tSpeaker ID={}'.format(evt.result.speaker_id))
     
    def conversation_transcriber_session_started_cb(evt: speechsdk.SessionEventArgs):
        print('SessionStarted event')
     
    def recognize_from_file():
        # This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
        speech_config = speechsdk.SpeechConfig(subscription="<KEY>", region="<REGION>")
        speech_config.speech_recognition_language="en-US"
        speech_config.set_property(property_id=speechsdk.PropertyId.SpeechServiceResponse_DiarizeIntermediateResults, value='true')
     
        audio_config = speechsdk.audio.AudioConfig(filename=r"FILE_PATH")
        conversation_transcriber = speechsdk.transcription.ConversationTranscriber(speech_config=speech_config, audio_config=audio_config)
     
        transcribing_stop = 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 transcribing_stop
            transcribing_stop = True
     
        # Connect callbacks to the events fired by the conversation transcriber
        conversation_transcriber.transcribed.connect(conversation_transcriber_transcribed_cb)
        conversation_transcriber.transcribing.connect(conversation_transcriber_transcribing_cb)
        conversation_transcriber.session_started.connect(conversation_transcriber_session_started_cb)
        conversation_transcriber.session_stopped.connect(conversation_transcriber_session_stopped_cb)
        conversation_transcriber.canceled.connect(conversation_transcriber_recognition_canceled_cb)
        # stop transcribing on either session stopped or canceled events
        conversation_transcriber.session_stopped.connect(stop_cb)
        conversation_transcriber.canceled.connect(stop_cb)
     
        conversation_transcriber.start_transcribing_async()
     
        # Waits for completion.
        while not transcribing_stop:
            time.sleep(.5)
     
        conversation_transcriber.stop_transcribing_async()
     
    # Main
     
    try:
        recognize_from_file()
    except Exception as err:
        print("Encountered exception. {}".format(err))
    
    
    

    output.

    User's image

    I hope this helps you. Thank you.


0 additional answers

Sort by: Most 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.