My event is getting cancelled while using microsoft speech service

Hari Narayan 0 Reputation points
2024-03-20T04:43:09.5466667+00:00

When I use my code in the remote server (virtual machine) the code is working fine (SPEECH KEYS and ENDPOINTS are working, using wav format audio file without noice) but when I am using the same code in local or in azure portal I am getting this error:

SessionStarted event Canceled event CLOSING on ConversationTranscriptionCanceledEventArgs(session_id=751531ddfea84904a646c43356cfd060, result=ConversationTranscriptionResult(result_id=49a65a470971423ea57cf231fcc161da, speaker_id=, text=, reason=ResultReason.Canceled)) SessionStopped event CLOSING on SessionEventArgs(session_id=751531ddfea84904a646c43356cfd060)

the code I used is: Below is the code:

import os

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('TRANSCRIBED:')

    if evt.result.reason == speechsdk.ResultReason.RecognizedSpeech:

        print('\tText={}'.format(evt.result.text))

        print('\tSpeaker ID={}'.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_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="SPEECHKEY", region="REGION")

    speech_config.speech_recognition_language="en-US"

 

    audio_config = speechsdk.audio.AudioConfig(filename="Conference.wav")

    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.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))

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

1 answer

Sort by: Most helpful
  1. navba-MSFT 16,695 Reputation points Microsoft Employee
    2024-03-20T06:22:05.2833333+00:00

    @Hari Narayan Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    • Could you please confirm if it was an Azure Virtual Machine ?
    • Are you using Speech Containers while running locally ?
    • You mentioned about the same code failing in Azure Portal, Could you please clarify which resource / how did you run this code in Azure ?
    • Could you please try to use the Azure Speech Studio and check if you encounter the same issue there too ?

    Action Plan:
    Could you please share the complete SDK logging from both working and non-working scenario ?

    https://learn.microsoft.com/en-us/azure/ai-services/speech-service/how-to-use-logging

    This will help us to compare and identify the cause.

    Sharing another thread where the similar issue was reported:
    https://learn.microsoft.com/en-us/answers/questions/1424128/facing-cancel-session-error-in-azure-speech-servic

    Awaiting your reply.

    0 comments No comments