Share via

Microsoft.CognitiveServices.Speech无法朗读中文

shangbin tian 96 Reputation points
2021-08-07T11:59:34.97+00:00

Microsoft.CognitiveServices.Speech无法朗读中文
代码如下:

    public static async Task SynthesisToSpeakerAsync()
        {
            // 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("XXXXXXXXXXXXXXXXXX", "westus2");

            // 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.
                Console.WriteLine("Type some text that you want to speak...");
                Console.Write("> ");
                string text = Console.ReadLine();
                using (var result = await synthesizer.SpeakTextAsync("这里是朗读的内容,this is aloud content"))
                {
                    if (result.Reason == ResultReason.SynthesizingAudioCompleted)
                    {
                        Console.WriteLine($"Speech synthesized to speaker for text [{text}]");
                    }
                    else if (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?");
                        }
                    }
                }

                // This is to give some time for the speaker to finish playing back the audio
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
        }

        static async Task Main()
        {
            await SynthesisToSpeakerAsync();
        }
Azure Speech in Foundry Tools
0 comments No comments

Answer accepted by question author

shangbin tian 96 Reputation points
2021-08-07T12:12:54.77+00:00

config.SpeechRecognitionLanguage = "zh-CN";
config.SpeechSynthesisLanguage= "zh-CN";
//https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support#neural-voices
config.SpeechSynthesisVoiceName = "zh-CN-XiaoxiaoNeural ";

ok

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.