|
本帖最后由 yangying 于 2013-6-4 17:04 编辑
1.我使用的环境是wien7 64位的操作系统,一下例子要确保计算机消息队列的安装,和语音识别的启用.如图:
[code=csharp]/// <summary>2.引用DLL文件 附件中有dll文件
/// 朗读
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//创建或打开消息队列
string path = @".\private$\queue";
MessageQueue mq = null;
if (MessageQueue.Exists(path))
{
mq = new MessageQueue(path);
}
else
{
mq = MessageQueue.Create(path, false);
mq.SetPermissions(".", MessageQueueAccessRights.FullControl);//获取对队列的附加权限的个人、组或计算机。
}
System.Messaging.Message mess = new System.Messaging.Message();
mess.Body = this.textBox1.Text.ToString();
mess.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(string) });
//向消息队列发送消息
mq.Send(mess);
//打开消息队列读取里面的消息
mq = new MessageQueue(path);
System.Messaging.Message messageread = mq.Receive();
messageread.Formatter=new System.Messaging.XmlMessageFormatter(new Type[]{typeof(string)});
ReadQueue(messageread.Body.ToString());
}
/// <summary>
/// 朗读
/// </summary>
/// <param name="message"></param>
private void ReadQueue(string message)
{
SpVoice sv = new SpVoice();
sv.Voice = sv.GetVoices(String.Empty, String.Empty).Item(0);
sv.Speak(message, SpeechVoiceSpeakFlags.SVSFlagsAsync);
}
[/code]
|
|