speech SDK is throwing error

Abdulla Rasfan 0 Reputation points
2025-06-08T08:29:30.8633333+00:00

hi,

i am trying to use the speech SDK as mentioned in the URL: https://learn.microsoft.com/en-us/azure/ai-services/speech-service/get-started-stt-diarization?tabs=macos&pivots=programming-language-python

initially i got the error :

2025-06-08 - 12:03:24 :start settign properties :diarization

Encountered exception. SpeechServiceResponse_DiarizeIntermediateResults

so i was able to solve it by using

speech_config.set_property_by_name(property_name='speechsdk.PropertyId.SpeechServiceResponse_DiarizeIntermediateResults',value='true')

instead of

speech_config.set_property(property_id=speechsdk.PropertyId.SpeechServiceResponse_DiarizeIntermediateResults, value='true')

however now i am facing another error:

Encountered exception. module 'azure.cognitiveservices.speech' has no attribute 'transcription'

at the point where in which the code is saying

conversation_transcriber = speechsdk.transcription.ConversationTranscriber(speech_config=speech_config, audio_config=audio_config)

full code for your reference and assistance

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('\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 "ENDPOINT"

# Replace with your own subscription key and endpoint, the endpoint is like : "https://YourServiceRegion.api.cognitive.microsoft.com"

print(time.strftime("%Y-%m-%d - %H:%M:%S :")+"start settign properties")

speech_config = speechsdk.SpeechConfig(host='ws://localhost:5106')

speech_config.speech_recognition_language="en-US"

print(time.strftime("%Y-%m-%d - %H:%M:%S :")+"start settign properties :diarization")

speech_config.set_property_by_name(property_name='speechsdk.PropertyId.SpeechServiceResponse_DiarizeIntermediateResults',value='true')

print(time.strftime("%Y-%m-%d - %H:%M:%S :")+"start settign properties :diarization DONE")

audio_config = speechsdk.audio.AudioConfig(filename="/cognitive/Completed/audio_files/sample.wav")

print(time.strftime("%Y-%m-%d - %H:%M:%S :")+"Recognizing...start")

conversation_transcriber = speechsdk.transcription.ConversationTranscriber(speech_config=speech_config, audio_config=audio_config)

print(time.strftime("%Y-%m-%d - %H:%M:%S :")+"Recognizing...started")

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))
Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
2,066 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Pavankumar Purilla 8,335 Reputation points Microsoft External Staff Moderator
    2025-06-09T05:11:07.8566667+00:00

    Hi Abdulla Rasfan,
    I reproduced the issue using the Azure Speech SDK with the ConversationTranscriber class and confirmed it works correctly with the following approach: ensure you are using the latest version of the SDK, set the diarization property via speech_config.set_property with PropertyId.SpeechServiceResponse_DiarizeIntermediateResults, and instantiate the ConversationTranscriber from the speechsdk.transcription namespace. The sample code processes audio input, outputs speaker diarization results, and completes without errors. Please verify your environment uses the latest SDK and your code follows this pattern.

    Here is a sample code snippet for your reference:

    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():
        # Replace below with your Azure Speech subscription key and region
        speech_key = "YourSubscriptionKeyHere"
        service_region = "YourServiceRegionHere"  # e.g., "eastus", "westus2"
        speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_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="sampledata_audiofiles_katiesteve.wav")
        conversation_transcriber = speechsdk.transcription.ConversationTranscriber(speech_config=speech_config, audio_config=audio_config)
        transcribing_stop = False
        def stop_cb(evt: speechsdk.SessionEventArgs):
            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)
        conversation_transcriber.session_stopped.connect(stop_cb)
        conversation_transcriber.canceled.connect(stop_cb)
        conversation_transcriber.start_transcribing_async()
        # Wait for completion.
        while not transcribing_stop:
            time.sleep(0.5)
        conversation_transcriber.stop_transcribing_async()
    # Main
    try:
        recognize_from_file()
    except Exception as err:
        print("Encountered exception. {}".format(err))
    
    
    

    Here is the output I received when running this code:User's image

    I hope this helps resolve your issue. Please ensure you have the latest Speech SDK installed, and feel free to reach out if you have any further questions.

    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.