本文介绍了通过Visual Basic 2005进行语音激活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我是否可以添加声音来控制温度
导入 System.Speech.Synthesis 公共 类 Form1 昏暗 FromSerialPort_Temp 暗 Thermistor_Temp( 15 ) As 整数 暗 Thermistor_R( 15 ) As 整数 暗 Circuit_Thermistor_R As Double 昏暗结果 Dim 扬声器 As 新 SpeechSynthesizer 私人 子 Form1_Load( ByVal 发件人 As 系统.对象, ByVal e As System.EventArgs)句柄 MyBase .Load ' [Timerspeak.Enabled = True 结束 子 私有 子 ReadSerialPortForTemp() FromSerialPort_Temp = SerialPort1.ReadExisting 如果 Len(FromSerialPort_Temp)<> 0 然后 ' 如果FromSerialPort_Temp不等于空白(已接通电源). TextBoxVoltage.Text = 0 . 01 * Convert.ToInt16(FromSerialPort_Temp.Substring( 2 , 3 ), 16 ) FromSerialPort_Temp = " U1000" ' 如果未读取任何内容并且使用FromSeriaPort_Temp = blank ,则分配"U1000" 结束 如果 结束 子 私有 Sub OpenPort1() 如果 SerialPort1.IsOpen 然后 SerialPort1.Close() 结束 如果 SerialPort1.PortName = " Com14" SerialPort1.BaudRate = 9600 SerialPort1.Parity = System.IO.Ports.Parity.None SerialPort1.DataBits = 8 SerialPort1.StopBits = System.IO.Ports.StopBits.One SerialPort1.RtsEnable = 真 SerialPort1.Open() 结束 子 私有 Sub ThermistorTable() Thermistor_Temp( 0 )= -10 Thermistor_R( 0 )= 42506 Thermistor_Temp( 1 )= -5 Thermistor_R( 1 )= 33892 Thermistor_Temp( 2 )= -0 Thermistor_R( 2 )= 27219 Thermistor_Temp( 3 )= 5 Thermistor_R( 3 )= 22021 Thermistor_Temp( 4 )= 10 Thermistor_R( 4 )= 17926 Thermistor_Temp( 5 )= 15 Thermistor_R( 5 )= 14674 Thermistor_Temp( 6 )= 20 Thermistor_R( 6 )= 12081 Thermistor_Temp( 7 )= 25 Thermistor_R( 7 )= 10000 Thermistor_Temp( 8 )= 30 Thermistor_R( 8 )= 8315 Thermistor_Temp( 9 )= 35 Thermistor_R( 9 )= 6948 Thermistor_Temp( 10 )= 40 Thermistor_R( 10 )= 5834 Thermistor_Temp( 11 )= 45 Thermistor_R( 11 )= 4917 Thermistor_Temp( 12 )= 50 Thermistor_R( 12 )= 4161 Thermistor_Temp( 13 )= 55 Thermistor_R( 13 )= 3535 Thermistor_Temp( 14 )= 60 Thermistor_R( 14 )= 3014 Thermistor_Temp( 15 )= 1000 Thermistor_R( 15 )= 1 Dim 计数器 As 整数 昏暗 Temperature_low 昏暗 Temperature_high 昏暗 Resistance_high 昏暗 Resistance_low 昏暗 Rnum1 Dim Rnum2 对于计数器= 0 >到 15 如果 CInt (TextBoxResistance.Text)> = Thermistor_R(Counter)然后 如果计数器<> 0 And 计数器<> 15 然后 Temperature_high =热敏电阻温度(计数器) Temperature_low = Thermistor_Temp(Counter- 1 ) 电阻低=热敏电阻R(计数器) 电阻上限=热敏电阻_R(计数器- 1 ) Rnum1 =电阻过高-TextBoxResistance.Text Rnum2 =电阻高-电阻低 结果= 2 . 5 + Math.Round(Temperature_low +( 5 * Rnum1/Rnum2), 1 ) TextBoxTemp.Text =结果& " C" 退出 用于 结束 如果 如果计数器= 0 >或 Counter = 15 然后 TextBoxTemp.Text = " 超出范围" 退出 用于 结束 如果 结束 如果 下一步 结束 子 私有 子 AcquireTemp() 调用 OpenPort1() TextBoxVoltage.Clear() TextBoxResistance.Clear() TextBoxTemp.Clear() SerialPort1.WriteLine(" U1" + vbCr) System.Threading.Thread.Sleep( 150 ) 致电 ReadSerialPortForTemp() 如果 Len(TextBoxVoltage.Text)= 0 >然后 ' 等待设备打开' 其他 Circuit_Thermistor_R = 10000 * TextBoxVoltage.Text/( 5 -TextBoxVoltage.Text) TextBoxResistance.Text = Math.Round(Circuit_Thermistor_R, 0 ) 致电 ThermistorTable() 结束 如果 结束 子 私人 子 Timer1_Tick( ByVal 发件人 As 系统.对象, ByVal e As System.EventArgs)句柄 Timer1.Tick 致电 AcquireTemp() 结束 子 私有 Sub BtnStart_Click( ByVal 发件人 As 系统.对象, ByVal e As System.EventArgs) Handles BtnStart.Click 致电 ToStartAP() 结束 子 私有 Sub ToStartAP() Dim StartAP() As 字节 = { & HFF,& H7和& H3} 调用 OpenPort1() SerialPort1.Write(StartAP, 0 ,StartAP.Length) System.Threading.Thread.Sleep( 300 ) TextBox1.Text = " AP已启动" 结束 子 ' 私有子Timerspeak_Tick(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理Timerspeak.Tick ' Speak() ' 结束子 ' 私人Sub Speak() ' 调用ThermistorTable() ' 如果TextBoxTemp.Text> 26然后 ' Speaker.Speak(TextBoxTemp.Text) ' 如果结束 ' 结束子 结束 类
解决方案
hi i wish to know whether can i add voice to control the temperature
Imports System.Speech.Synthesis Public Class Form1 Dim FromSerialPort_Temp Dim Thermistor_Temp(15) As Integer Dim Thermistor_R(15) As Integer Dim Circuit_Thermistor_R As Double Dim Result Dim Speaker As New SpeechSynthesizer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '[Timerspeak.Enabled = True End Sub Private Sub ReadSerialPortForTemp() FromSerialPort_Temp = SerialPort1.ReadExisting If Len(FromSerialPort_Temp) <> 0 Then 'if FromSerialPort_Temp NOT equal to blank (power connected). TextBoxVoltage.Text = 0.01 * Convert.ToInt16(FromSerialPort_Temp.Substring(2, 3), 16) FromSerialPort_Temp = "U1000" 'assign with "U1000" if nothing is read and FromSeriaPort_Temp=blank End If End Sub Private Sub OpenPort1() If SerialPort1.IsOpen Then SerialPort1.Close() End If SerialPort1.PortName = "Com14" SerialPort1.BaudRate = 9600 SerialPort1.Parity = System.IO.Ports.Parity.None SerialPort1.DataBits = 8 SerialPort1.StopBits = System.IO.Ports.StopBits.One SerialPort1.RtsEnable = True SerialPort1.Open() End Sub Private Sub ThermistorTable() Thermistor_Temp(0) = -10 Thermistor_R(0) = 42506 Thermistor_Temp(1) = -5 Thermistor_R(1) = 33892 Thermistor_Temp(2) = -0 Thermistor_R(2) = 27219 Thermistor_Temp(3) = 5 Thermistor_R(3) = 22021 Thermistor_Temp(4) = 10 Thermistor_R(4) = 17926 Thermistor_Temp(5) = 15 Thermistor_R(5) = 14674 Thermistor_Temp(6) = 20 Thermistor_R(6) = 12081 Thermistor_Temp(7) = 25 Thermistor_R(7) = 10000 Thermistor_Temp(8) = 30 Thermistor_R(8) = 8315 Thermistor_Temp(9) = 35 Thermistor_R(9) = 6948 Thermistor_Temp(10) = 40 Thermistor_R(10) = 5834 Thermistor_Temp(11) = 45 Thermistor_R(11) = 4917 Thermistor_Temp(12) = 50 Thermistor_R(12) = 4161 Thermistor_Temp(13) = 55 Thermistor_R(13) = 3535 Thermistor_Temp(14) = 60 Thermistor_R(14) = 3014 Thermistor_Temp(15) = 1000 Thermistor_R(15) = 1 Dim Counter As Integer Dim Temperature_low Dim Temperature_high Dim Resistance_high Dim Resistance_low Dim Rnum1 Dim Rnum2 For Counter = 0 To 15 If CInt(TextBoxResistance.Text) >= Thermistor_R(Counter) Then If Counter <> 0 And Counter <> 15 Then Temperature_high = Thermistor_Temp(Counter) Temperature_low = Thermistor_Temp(Counter - 1) Resistance_low = Thermistor_R(Counter) Resistance_high = Thermistor_R(Counter - 1) Rnum1 = Resistance_high - TextBoxResistance.Text Rnum2 = Resistance_high - Resistance_low Result = 2.5 + Math.Round(Temperature_low + (5 * Rnum1 / Rnum2), 1) TextBoxTemp.Text = Result & "C" Exit For End If If Counter = 0 Or Counter = 15 Then TextBoxTemp.Text = "Out of Range" Exit For End If End If Next End Sub Private Sub AcquireTemp() Call OpenPort1() TextBoxVoltage.Clear() TextBoxResistance.Clear() TextBoxTemp.Clear() SerialPort1.WriteLine("U1" + vbCr) System.Threading.Thread.Sleep(150) Call ReadSerialPortForTemp() If Len(TextBoxVoltage.Text) = 0 Then ' wait for the equipment to be turned on ' Else Circuit_Thermistor_R = 10000 * TextBoxVoltage.Text / (5 - TextBoxVoltage.Text) TextBoxResistance.Text = Math.Round(Circuit_Thermistor_R, 0) Call ThermistorTable() End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Call AcquireTemp() End Sub Private Sub BtnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart.Click Call ToStartAP() End Sub Private Sub ToStartAP() Dim StartAP() As Byte = {&HFF, &H7, &H3} Call OpenPort1() SerialPort1.Write(StartAP, 0, StartAP.Length) System.Threading.Thread.Sleep(300) TextBox1.Text = "AP Started" End Sub 'Private Sub Timerspeak_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timerspeak.Tick ' Speak() 'End Sub 'Private Sub Speak() ' Call ThermistorTable() ' If TextBoxTemp.Text > 26 Then ' Speaker.Speak(TextBoxTemp.Text) ' End If 'End Sub End Class
解决方案
这篇关于通过Visual Basic 2005进行语音激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!