Пример #1
0
        /// <summary>
        /// 生成语音文件的方法
        /// </summary>
        /// <param name="text"></param>
        private static void SaveFile(string text)
        {
            using (System.Speech.Synthesis.SpeechSynthesizer speechSyn = new System.Speech.Synthesis.SpeechSynthesizer())
            {
                speechSyn.Volume = 100;
                speechSyn.Rate   = 0;
                string strPath = @"F:\研发一部\5.源代码\6.组件库\Lxsh.Project\Lxsh.Project.SpeechSynthesizer.Demo\bin\Debug\1.mp3";
                speechSyn.SetOutputToWaveFile(strPath);

                speechSyn.Speak(text);
                speechSyn.SetOutputToNull();
            }
        }
Пример #2
0
 private void speak(bool bAsync, System.Speech.Synthesis.PromptBuilder pb)
 {
     try
     {
         if (bSaveFile)
         {
             ss.SetOutputToNull();
             delOutFile();
             ss.SetOutputToWaveFile(strOutputFile);
         }
         if (bAsync)
         {
             ss.SpeakAsync(pb);
         }
         else
         {
             ss.Speak(pb);
         }
     }
     catch (Exception ex)
     {
         speak("An error occured:" + ex.Message, false);
     }
 }