1. 要在C#中进行中文语音播放,需要安装微软的Speech Application SDK(SASDK),可以在这里下载: http://www.microsoft.com/speech/download/sdk51/,需要安装这两个文件Speech SDK 5.1和5.1 2. 在C#程序中添加如下引用,并在代码中添加using System.Speech.Synthesis; 3. 对于机器人运行状态的订阅,可以在上位机登录上机器人系统后,添加如下订阅 void subscribe() { controller.Rapid.ExecutionStatusChanged += new EventHandler<ExecutionStatusChangedEventArgs>(exe_StateChanged); //添加对运行模式的订阅 } 4. 在对应响应事件中,添加语音输出 private void UpdateGUIexe_state(object sender, System.EventArgs e) { this.label18.Text = controller.Rapid.ExecutionStatus.ToString(); string s1 = ''; if (label18.Text == 'Running') { s1 = '机器人启动'; } if (label18.Text == 'Stopped') { s1 = '机器人停止运动'; } textBox2.Text = s1; SpeechSynthesizer speech = new SpeechSynthesizer(); speech.Volume = 100; //音量 speech.Rate = 1; //朗读速度 speech.SelectVoice('Microsoft Simplified Chinese'); speech.SpeakAsync(s1); } 5. 对于其他变量/语句的语音输出,方法类似,可以通过以下代码进行订阅 rd = controller.Rapid.GetRapidData('T_ROB1', 'm1', 'count'); rd.ValueChanged += new EventHandler<DataValueChangedEventArgs>(valueChanged); 如何成为优秀的电气工程师?
|
|
来自: 阿明哥哥资料区 > 《83.机器人教学与调试》