欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > C# >内容正文

C#

微软语音合成朗读c#

发布时间:2024/3/24 C# 60 豆豆
生活随笔 收集整理的这篇文章主要介绍了 微软语音合成朗读c# 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

 经过测试,发现微软的语音服务在发音方面略强于科大讯飞。

using Microsoft.CognitiveServices.Speech; ... public async Task SynthesisToSpeakerAsync(string text){if (text == ""){textBox1.Text += $"识别读取文本: [{text}]\r\n";return;}var config = SpeechConfig.FromSubscription("6666666666666666", "westus2");config.SpeechRecognitionLanguage = "zh-CN";config.SpeechSynthesisLanguage = "zh-CN";//https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support#neural-voicesconfig.SpeechSynthesisVoiceName = comboBox1.Text;synthesizer = null;using (synthesizer = new SpeechSynthesizer(config)){using (var result = await synthesizer.SpeakTextAsync(text)){if (result.Reason == ResultReason.SynthesizingAudioCompleted){AudioCompleted = true;textBox1.Text += $"识别读取文本: [{text}]\r\n";}else if (result.Reason == ResultReason.Canceled){var cancellation = SpeechSynthesisCancellationDetails.FromResult(result);textBox1.Text += ($"CANCELED: Reason={cancellation.Reason}\r\n");if (cancellation.Reason == CancellationReason.Error){textBox1.Text += ($"CANCELED: ErrorCode={cancellation.ErrorCode}\r\n");textBox1.Text += ($"CANCELED: ErrorDetails=[{cancellation.ErrorDetails}]\r\n");textBox1.Text += ($"CANCELED: Did you update the subscription info?\r\n");}}}// This is to give some time for the speaker to finish playing back the audio}}

总结

以上是生活随笔为你收集整理的微软语音合成朗读c#的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。