System.Speech.Synthesis.SpeechSynthesizer SpeechSynthesizer = new System.Speech.Synthesis.SpeechSynthesizer();
  public void boFangYuyin() {
            try
            {
                System.Threading.Tasks.Task.Factory.StartNew(boFangYuyinAction);
            }
            catch (Exception ex)
            {
                EduInterface.IEx.Handle(ex, FloatToolsErrCode.语音播放学生姓名);
            }
        }
        public void boFangYuyinAction() {
            SpeechSynthesizer.Rate = 0;
            SpeechSynthesizer.Speak("正在播放语音中");
        }
        protected override void OnClosed(EventArgs e)
        {

            base.OnClosed(e);
            SpeechSynthesizer.Pause();//要有这句,否则播放中突然关闭窗体会报错
            SpeechSynthesizer.Dispose();//释放资源
           
        }
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐