Author Topic: Speech Recognition  (Read 2980 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Speech Recognition
« on: June 21, 2018, 07:53:26 AM »
A fun little experiment on speech control. This is definitely not up to the caliber of the more advanced speech recognition devices, but does work.

- In Solution Explorer, right click the AdvancedHMI project and select Add reference
- Select System.Speech reference from the list
- In Solution Explorer right click the MainForm.vb and select View Code
- Add this code:
Code: [Select]
    Private WithEvents sp As New System.Speech.Recognition.SpeechRecognitionEngine(New System.Globalization.CultureInfo("en-US"))

    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        '// Create And load a dictation grammar.
        sp.LoadGrammar(New System.Speech.Recognition.DictationGrammar())

        '// Configure input to the speech recognizer.
        sp.SetInputToDefaultAudioDevice()

        '// Start asynchronous, continuous speech recognition.
        sp.RecognizeAsync(System.Speech.Recognition.RecognizeMode.Multiple)
    End Sub

    Private Sub sp_SpeechRecognized(sender As Object, e As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles sp.SpeechRecognized
        Me.Text = e.Result.Text

        If e.Result.Text.IndexOf("press", StringComparison.CurrentCultureIgnoreCase) >= 0 And e.Result.Text.IndexOf("button", StringComparison.CurrentCultureIgnoreCase) >= 0 Then
            '* Write the button press bit to the PLC
            '* EthernetIPforCLXCom1.Write("MyButton","1")
            MsgBox("Button will be pressed")
        End If
    End Sub

- Run the application and talk to it. You will see the result in the form's title bar.



The next step for improved recognition would be to use Microsoft's Azure services. I tried this demo and it works quite well:

https://azure.microsoft.com/en-us/services/cognitive-services/speech-to-text/
« Last Edit: June 21, 2018, 08:00:33 AM by Archie »