示例#1
0
        // Speech synthesis get available voices
        public static async Task SynthesisGetAvailableVoicesAsync()
        {
            // Creates an instance of a speech config with specified subscription key and service region.
            // Replace with your own subscription key and service region (e.g., "westus").
            // The default language is "en-us".
            var config = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");

            // Creates a speech synthesizer
            using (var synthesizer = new SpeechSynthesizer(config, null as AudioConfig))
            {
                Console.WriteLine("Enter a locale in BCP-47 format (e.g. en-US) that you want to get the voices of, or enter empty to get voices in all locales.");
                Console.Write("> ");
                string text = Console.ReadLine();

                using (var result = await synthesizer.GetVoicesAsync(text))
                {
                    if (result.Reason == ResultReason.VoicesListRetrieved)
                    {
                        Console.WriteLine("Voices successfully retrieved, they are:");
                        foreach (var voice in result.Voices)
                        {
                            Console.WriteLine(voice.Name);
                        }
                    }
                    else if (result.Reason == ResultReason.Canceled)
                    {
                        Console.WriteLine($"CANCELED: ErrorDetails=[{result.ErrorDetails}]");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }
                }
            }
        }