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

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();
        }

 

posted @ 2021-08-23 14:08  txwtech  阅读(1068)  评论(0编辑  收藏  举报