WPF 语音读取某一段文字

      ///<summary>
        /// 调用系统 语音朗读   备注 该方法只支持.net 4.0 版本以上
        /// </summary>
        /// <param name="type">错误类型</param>
        /// <param name="isAsync">是否同步朗读</param>
        /// <param name="CardCode">卡片编号/卡片持有者</param>
        void PlaySpeekMouth(Classes.AlarmType type, bool isAsync, string CardCode)
        {
            using (SpeechSynthesizer synthesizer = new SpeechSynthesizer())
            {
                synthesizer.Volume = 100;   //音量 0~100   最大只能100
                synthesizer.Rate = 0;   //  语速 -10~10    0 中等
                string titleMessage = string.Empty;
                switch (type)
                {
                    case Classes.AlarmType.Broken:
                        if (isAsync)
                        {
                            //异步朗读
                            synthesizer.SpeakAsync("报警!发现卡片编号为:" + CardCode + " 出现错误区域!");
                        }
                        else
                        {  //同步朗读
                            synthesizer.Speak("报警!发现卡片编号为:" + CardCode + " 出现错误区域!");
                        }
                        break;
                    case Classes.AlarmType.Disappear:
                        if (isAsync)
                        {
                            //异步朗读
                            synthesizer.SpeakAsync("报警!发现卡片编号为:" + CardCode + " 出现错误卡片消失!");
                        }
                        else
                        {  //同步朗读
                            synthesizer.Speak("报警!发现卡片编号为:" + CardCode + " 出现错误卡片消失!");
                        }
                        break;
                }
            }

        }

 

然后在调用方法:

      //语音报读取  相关信息
                    PlaySpeekMouth(Classes.AlarmType.Broken, false, vs.CARDCODE);

posted @ 2012-04-24 16:02  在 水 一 方  阅读(1946)  评论(4编辑  收藏  举报