//sample code from //https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/how-to-speech-synthesis?tabs=browserjs%2Cterminal&pivots=programming-language-csharp
// Creates a speech synthesizer using the default speaker as audio output. using (var synthesizer = new SpeechSynthesizer(config)) { // Receive a text from console input and synthesize it to speaker. using (var result = await synthesizer.SpeakTextAsync(text)) { if (result.Reason == ResultReason.SynthesizingAudioCompleted) { //save wav here //Console.WriteLine($"Speech synthesized to speaker for text [{text}]"); System.IO.File.WriteAllBytes(path, result.AudioData); } elseif (result.Reason == ResultReason.Canceled) { var cancellation = SpeechSynthesisCancellationDetails.FromResult(result); Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
if (cancellation.Reason == CancellationReason.Error) { Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}"); Console.WriteLine($"CANCELED: ErrorDetails=[{cancellation.ErrorDetails}]"); Console.WriteLine($"CANCELED: Did you update the subscription info?"); } } } } }