本文介绍了用我的程序编程语音识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我可以知道是否可以在程序中添加语音识别吗?
如果是,我可以在哪里添加它?
如果无法完成,必须做些什么才能具有语音识别功能?

Hi,
may I know if I can add speech recognition to my program?
If yes, may I know where do I add it?
If it cannot be done what must be done to be able to have speech recognition?

Imports System.Speech.Synthesis

Public Class Form1
    Dim FromSerialPort1 As String
    Dim XX(100) As Integer
    Dim YY(100) As Integer
    Dim ZZ(100) As Integer
    Dim Flag As Integer
    Dim Speaker_Flag As Integer = 0
    Dim FromSerialPort_Temp

    Dim Thermistor_Temp(15)
    Dim Thermistor_R(15)
    Dim Circuit_Thermistor_R As Double
    Dim Result
    Dim Speaker As New SpeechSynthesizer
    Dim counter As Integer
    Dim totalrows As Integer
    Dim NextRecord As Integer
    Dim ConObject As New OleDb.OleDbConnection
    Dim dSet As New DataSet
    Dim dAdapter As OleDb.OleDbDataAdapter
    Dim sel As String
    Dim RowNo As Integer = 0
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        TimerSpeak2.Enabled = True
        Timer2.Enabled = True


        If SerialPort1.IsOpen Then
            SerialPort1.Close()
        End If

        SerialPort1.PortName = "Com9"
        SerialPort1.BaudRate = 115200
        SerialPort1.DataBits = 8
        SerialPort1.StopBits = IO.Ports.StopBits.One
        SerialPort1.RtsEnable = True

        SerialPort1.Open()


        ConObject.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data source=C:\Documents and Settings\tians\My Documents\Visual Studio 2005\Projects\Sensor\Sensor\Sensor1.mdb"

        ConObject.Open()

        sel = "SELECT*FROM Table1"
        dAdapter = New OleDb.OleDbDataAdapter(sel, ConObject)
        dAdapter.Fill(dSet, "Sensor1")
        ConObject.Close()

        totalrows = dSet.Tables("Sensor1").Rows.Count



    End Sub
    Private Sub BtnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStop.Click
        Call ToStopAP()
    End Sub

    Private Sub BtnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRead.Click
        Timer1.Enabled = True

        Dim ReadAP() As Byte = {&HFF, &H8, &H7, &H0, &H0, &H0, &H0}

        Dim RxReadAP(10) As Byte

        SerialPort1.Write(ReadAP, 0, ReadAP.Length)

        System.Threading.Thread.Sleep(8)

        SerialPort1.Read(RxReadAP, 0, 10)
        TextBox1.Text = RxReadAP(3)
        TextBoxXX.Text = RxReadAP(4)
        TextBoxYY.Text = RxReadAP(5)
        TextBoxZZ.Text = RxReadAP(6)
    End Sub
    Private Sub ToReadAP()

        Dim ReadAP() As Byte = {&HFF, &H8, &H7, &H0, &H0, &H0, &H0}

        Dim RxReadAP(10) As Byte

        SerialPort1.Write(ReadAP, 0, ReadAP.Length)

        System.Threading.Thread.Sleep(8)

        SerialPort1.Read(RxReadAP, 0, 10)

        TextBox1.Text = RxReadAP(3)
        TextBoxXX.Text = RxReadAP(4)
        TextBoxYY.Text = RxReadAP(5)
        TextBoxZZ.Text = RxReadAP(6)
    End Sub

    Private Sub ToStartAP()
        Dim StartAP() As Byte = {&HFF, &H7, &H3}

        SerialPort1.Write(StartAP, 0, StartAP.Length)

        System.Threading.Thread.Sleep(300)

        TextBox1.Text = "AP Started"
    End Sub

    Private Sub ToStopAP()
        Dim StopAP() As Byte = {&HFF, &H9, &H3}

        SerialPort1.Write(StopAP, 0, StopAP.Length)

        System.Threading.Thread.Sleep(300)

        TextBox1.Text = "Stop"

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Call ToReadAP()
    End Sub

    Private Sub Speak()
        Call ToReadAP()
        If TextBoxXX.Text > 200 Then
            TextBoxup.Text = ""
            TextBoxup.Text = "Up" + TextBoxXX.Text
            TextBoxup.Refresh()
            Speaker.Speak(TextBoxup.Text)
        End If

        If TextBoxXX.Text > 0 And TextBoxXX.Text < 60 Then
            TextBoxdown.Text = ""
            TextBoxdown.Text = "Down" + TextBoxXX.Text
            TextBoxdown.Refresh()
            Speaker.Speak(TextBoxdown.Text)

        End If

        If TextBoxXX.Text > 0 And TextBoxXX.Text < 60 And TextBoxXX.Text < 250 Then
            TextBoxLeft.Text = ""
            TextBoxLeft.Text = "Left" + TextBoxXX.Text
            TextBoxLeft.Refresh()
            Speaker.Speak(TextBoxLeft.Text)
        End If

        If TextBoxXX.Text > 0 And TextBoxXX.Text < 60 And TextBoxXX.Text < 150 Then
            TextBoxRight.Text = ""
            TextBoxRight.Text = "Right" + TextBoxXX.Text
            TextBoxRight.Refresh()
            Speaker.Speak(TextBoxRight.Text)

        End If
    End Sub

    Private Sub TimerSpeak_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerSpeak.Tick
        Speak()
    End Sub
    Private Sub ReadSerialPortForTemp()
        FromSerialPort_Temp = SerialPortTemp.ReadExisting

        If Len(FromSerialPort_Temp) <> 0 Then
            TextBoxVoltage.Text = 0.01 * Convert.ToInt16(FromSerialPort_Temp.SubString(2, 3), 16)

        Else
            FromSerialPort_Temp = "U1000"
        End If
    End Sub
    Private Sub OpenPort1()
        If SerialPortTemp.IsOpen Then
            SerialPortTemp.Close()
        End If

        SerialPortTemp.PortName = "Com12"
        SerialPortTemp.BaudRate = 9600
        SerialPortTemp.Parity = System.IO.Ports.Parity.None
        SerialPortTemp.DataBits = 8
        SerialPortTemp.StopBits = System.IO.Ports.StopBits.One

        SerialPortTemp.RtsEnable = True
        SerialPortTemp.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 Temperature_low
        Dim Temperature_high
        Dim Resistance_low
        Dim Resistance_high
        Dim Rnum1
        Dim Rnum2


        Dim r As Integer = CInt(TextBoxResistance.Text)
        Dim idx As Integer = 0
        While r < Thermistor_R(idx) And idx < 15
            idx += 1
        End While
        If (idx = 0 Or idx = 15) Then
            TextBoxTemp.Text = "Out Of Range"
        Else
            Temperature_high = Thermistor_Temp(idx)
            Temperature_low = Thermistor_Temp(idx - 1)
            Resistance_low = Thermistor_R(idx)
            Resistance_high = Thermistor_R(idx - 1)
            Rnum1 = Resistance_high - r
            Rnum2 = Resistance_high - Resistance_low
            Result = 2.5 + Math.Round(Temperature_low + (5 * Rnum1 / Rnum2), 1)
            TextBoxTemp.Text = Result & "C"
        End If
        If Result >= 0 Then
            TextBox.Text = ""
            TextBox.Text = "Your Temperature is " + TextBoxTemp.Text
            TextBox.Refresh()
            Speaker.Speak(TextBox.Text)


        End If



    End Sub


    Private Sub TimerTemp_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerTemp.Tick
        Call OpenPort1()

        TextBoxVoltage.Clear()
        TextBoxResistance.Clear()
        TextBoxTemp.Clear()
        SerialPortTemp.WriteLine("U1" + vbCr)
        System.Threading.Thread.Sleep(150)


        Call ReadSerialPortForTemp()

        If Len(TextBoxVoltage.Text) = 0 Then
        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 TimerSpeak2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerSpeak2.Tick

        If CheckBox1.Checked = True Then
            TimerTemp.Enabled = True
            CheckBox2.Checked = False
            TimerCount.Enabled = False

        Else
            CheckBox1.Checked = False
            Timer1.Enabled = False
            TimerSpeak.Enabled = False
            TimerTemp.Enabled = False


            If CheckBox2.Checked = True Then
                TimerTemp.Enabled = False
                TimerSpeak.Enabled = True
            End If



        End If

    End Sub

    Private Sub BtnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart.Click
        Call ToStartAP()
        Timer1.Enabled = True
        Timer2.Enabled = False

    End Sub

    Private Sub TimerCount_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerCount.Tick
        Dim Counter As Integer
        TimerCount.Interval = 100



        If Counter <= 100 Then
            Call ToReadAP()

            XX(Counter) = TextBoxXX.Text
            YY(Counter) = TextBoxYY.Text
            ZZ(Counter) = TextBoxZZ.Text
        Else

            If XX(100) > XX(75) * 0.9 And XX(100) < XX(75) * 1.1 Then
                If XX(76) > XX(50) * 0.9 And XX(76) < XX(50) * 1.1 Then
                    If XX(51) > XX(25) * 0.9 And XX(51) < XX(25) * 1.1 Then

                    End If
                End If
            End If

            Timer1.Enabled = True
            TimerCount.Enabled = False
        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim cBuilder As New OleDb.OleDbCommandBuilder(dAdapter)
        Dim dsNewRow As DataRow

        dsNewRow = dSet.Tables("Sensor1").NewRow()
        dsNewRow.Item("Temperature") = TextBoxTemp.Text
        dSet.Tables("Sensor1").Rows.Add(dsNewRow)
        dAdapter.Fill(dSet, "Sensor1")
        dSet.Tables("Sensor1").Rows(RowNo).Item("Temperature") = TextBoxTemp.Text
        dAdapter.Update(dSet, "Sensor1")
        dSet.Clear()
    End Sub

    Private Sub BtnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDisplay.Click
        Dim counter As Integer
        Dim temp As String

        TextBox7.Clear()

        totalrows = dSet.Tables("Sensor1").Rows.Count

        For counter = 0 To totalrows - 1
            temp = dSet.Tables("Sensor1").Rows(counter).Item("Temperature")

            TextBox7.Text = TextBox7.Text + temp + vbNewLine

        Next counter
    End Sub

End Class

推荐答案


这篇关于用我的程序编程语音识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 01:34