• 周三. 2月 28th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

c#语音播报播放语音功能

admin

11月 28, 2021

c#语音播报播放语音功能

public void Speaking(string saying)
        {
            string say = saying;
            Task task = new Task(() =>
            {
                SpeechSynthesizer speech = new SpeechSynthesizer();
                speech.Volume = 100; //音量
                CultureInfo keyboardCulture = System.Windows.Forms.InputLanguage.CurrentInputLanguage.Culture;
                InstalledVoice neededVoice = speech.GetInstalledVoices(keyboardCulture).FirstOrDefault();
                if (neededVoice == null)
                {
                    say = "未知操作";
                }
                else
                {
                    speech.SelectVoice(neededVoice.VoiceInfo.Name);
                }

                speech.Speak(say);
            });
            task.Start();
        }
欢迎讨论,相互学习。
[email protected]

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注