How to poll asynchronous speech synthesis for status in Python

yme 10 Reputation points
2023-02-07T12:04:47.82+00:00

Hello,

I have an object of type speechsdk.SpeechSynthesizer which I am running asynchronous speech synthesis with speech_synthesizer.speak_ssml_async() on, and I want to be able to tell when the synthesis has completed (i.e. how to poll it for an updated result). I can call result.get() but it never changes from ResultReason.SynthesizingAudioStarted. I would like to, for example, be able to poll something and get ResultReason.SynthesizingAudioCompleted once the audio synthesis is complete.

Code to reproduce is below. Polling the result object always prints ResultReason.SynthesizingAudioStarted, even after audio synthesis is clearly finished.

Thank you!


text = 'READ THIS MESSAGE!'

speech_config = speechsdk.SpeechConfig(
    subscription=config['key'], region=config['region'])
audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)

speech_synthesizer = speechsdk.SpeechSynthesizer(
    speech_config=speech_config, audio_config=audio_config)

result = speech_synthesizer.start_speaking_ssml_async(f"""
    
    <speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="zh-CN">
        <voice name="zh-CN-XiaoxiaoNeural">
            <mstts:express-as style="hat" styledegree="1.5">
                <prosody rate="-3%" pitch="+0%" range="+5%">
                    {text}
                </prosody>
            </mstts:express-as>
        </voice>
    </speak>
""")
while True:
    print(result.get())
Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,379 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,806 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. yme 10 Reputation points
    2023-02-08T10:47:11.8733333+00:00

    Hello, I answered my question: you can get this status by connecting callback functions to the speech synthesizer:

    https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/python/console/speech_synthesis_sample.py#L409

    0 comments No comments