文本转语音,人声播报,如下图,点击Speak按钮 即可播报 找例子网 
 
  public class SpeakHelper  {    // public static SpeechSynthesizer Synth = new SpeechSynthesizer();    public static SpeechSynthesizer Synth;    private static Thread _thread;    private static string _contentThread;    /// <summary>    /// 文本转语音    /// </summary>    /// <param name="content">文本内容</param>    public static void SpeekContent(string content)    {      _contentThread = content;      _thread = new Thread(SpeakContentThread);      _thread.IsBackground = true;      _thread.Start();    }    private static void SpeakContentThread()    {      try      {        if (Synth != null)        {          Synth.Dispose();        }        Synth = new SpeechSynthesizer();        Synth.Rate = -1;        Synth.Speak(_contentThread);      }      catch (Exception)      {      }    }    //停止播放    public static void StopSpeak()    {      try      {        if (Synth != null)        {          Synth.Dispose();//释放 SpeechSynthesizer 在会话期间使用的对象并释放资源        }        if (_thread != null)        {          _thread.Abort();//终止线程        }      }      catch (Exception)      { }    }  }

 
  
					
				
评论