You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.1 KiB
74 lines
1.1 KiB
using System.Speech.Synthesis;
|
|
|
|
namespace EC.AutoWeightServer.IfManager.Speech
|
|
{
|
|
public class SpeakManager
|
|
{
|
|
private SpeechSynthesizer _curSpeech;
|
|
|
|
public SpeakManager()
|
|
{
|
|
}
|
|
|
|
#region Start & Stop Server
|
|
|
|
/// <summary>
|
|
/// 开启连接
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public void StartServer()
|
|
{
|
|
_curSpeech = new SpeechSynthesizer
|
|
{
|
|
Volume = 100,//音量 [0, 100]
|
|
Rate = 0//语速 [-10, 10]
|
|
};
|
|
}
|
|
|
|
public void ReStartServer()
|
|
{
|
|
StopServer();
|
|
StartServer();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭连接
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public void StopServer()
|
|
{
|
|
if (!IsOpen())
|
|
return;
|
|
_curSpeech.Pause();
|
|
_curSpeech.Dispose();
|
|
_curSpeech = null;
|
|
}
|
|
|
|
#endregion Start & Stop Server
|
|
|
|
#region Tool Methods
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
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
|
|
}
|
|
}
|