语音播报终端基于Windows TTS SDK,即Text To Speech。使用ActiveMQ作为播报数据消息服务,各终端通过实时监听数据广播地址获取数据信息,再通过TTS进行语音播报。
语音播报终端主要功能:
1.通过CMS监听消息服务广播地址,
2.通过TTS播报文本数据信息。
源程序:
1.监听广播地址
public void startListener(string url, string username, string password, string receiveQueueStr)
{
try
{
//Create the Connection Factory
IConnectionFactory factory = new ConnectionFactory(url);
IConnection connection = factory.CreateConnection(username, password);
connection.Start();
//Create the Session
session = connection.CreateSession();
//Create the Consumer
consumer = session.CreateConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic(receiveQueueStr), null);
consumer.Listener += new MessageListener(consumer_Listener);
}
catch
{
throw;
}
}
2.播放语音
/*
*
*
* 播放声音
*
*
*/
public void play(string text)
{
SpeechSynthesizer reader = new SpeechSynthesizer();
try
{
reader.Rate = defaultSpeed;
reader.SelectVoice(defaultVoice);
reader.SpeakAsync(text);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
reader.Dispose();
}
}