question

StephenStewart-6080 avatar image
0 Votes"
StephenStewart-6080 asked StephenStewart-6080 answered

SpeechSynthesizer.SpeakTextAsync does not return value

I am having a problem using Azure Speech Synthesizer.

I pass in a string to SpeechSynthesizer.SpeakTextAsync, the speech is synthesized but the next line of code is not reached as the task does not complete.

 public async Task SynthesizeAudioAsync(string text)
         {
             using var synthesizer = new SpeechSynthesizer(_config);
             Debug.WriteLine("Synthesizing");
             using var result = await synthesizer.SpeakTextAsync(text);
             Debug.WriteLine("Synthesized"); //This line is not reached
         }

I am using the C# SDK

Is there an issue with Azure speech services at the moment? Or am I doing something wrong? Thanks!

dotnet-csharpwindows-wpfazure-speech
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I've created a small sample app that highlights the issue I am facing. When you run the app it will fetch the audio and play through the default audio output; you will hear "Order received". During this time the MainWindow will be unresponsive, and will continue to be unresponsive after the audio is synthesized.

There's something I am doing wrong, I am unable to figure out what it is. Also, if anyone manages to see the problem and has any hints as to how to debug in the future, I would appreciate it. I have experience in other programming languages but I am new to C# and .NET

Sample App



@romungi-MSFT The sample you linked to seems to point back to this thread

0 Votes 0 ·

@StephenStewart-6080 Apologies for that, I have updated the right github repo to check now,


0 Votes 0 ·
StephenStewart-6080 avatar image
0 Votes"
StephenStewart-6080 answered

I updated my sample app with the fix. I was running the initial async task TriggerEventAsync wrong

 //Switched this line
 TriggerEventAsync(eventManager).GetAwaiter().GetResult();
    
 //For this line
 Task.Run(async () => await TriggerEventAsync(eventManager));
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

romungi-MSFT avatar image
1 Vote"
romungi-MSFT answered romungi-MSFT edited

@StephenStewart-6080 I think the service is not having any issues currently, so that should not be an issue.
Also, I think you are calling SpeakTextAsync correctly but I am not sure about the rest of the config in the call. I think you could use this sample and check the result of your call and play the audio with your default audio output.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.