using System.Speech.Synthesis;
namespace EC.AutoWeightServer.IfManager.Speech
{
public class SpeakManager
{
private SpeechSynthesizer _curSpeech;
public SpeakManager()
{
}
#region Start & Stop Server
///
/// 开启连接
///
///
public void StartServer()
{
_curSpeech = new SpeechSynthesizer
{
Volume = 100,//音量 [0, 100]
Rate = 0//语速 [-10, 10]
};
}
public void ReStartServer()
{
StopServer();
StartServer();
}
///
/// 关闭连接
///
///
public void StopServer()
{
if (!IsOpen())
return;
_curSpeech.Pause();
_curSpeech.Dispose();
_curSpeech = null;
}
#endregion Start & Stop Server
#region Tool Methods
///
///
public void Speak(string text)
{
if (!IsOpen())
return;
_curSpeech.Speak(text);
}
public void SpeakAsync(string text, bool cancelAll = true)
{
if (cancelAll)
_curSpeech.SpeakAsyncCancelAll();
_curSpeech.SpeakAsync(text);
}
public bool IsOpen()
{
return _curSpeech != null;
}
#endregion Tool Methods
}
}