daily pastebin goal
25%
SHARE
TWEET

Voice Recognition

Robomatics Jan 11th, 2013 13,320 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Speech
  2.  
  3. Public Class Form1
  4.  
  5.     Dim WithEvents reco As New Recognition.SpeechRecognitionEngine
  6.  
  7.     Private Sub SetColor(ByVal color As System.Drawing.Color)
  8.  
  9.         Dim synth As New Synthesis.SpeechSynthesizer
  10.  
  11.         synth.SpeakAsync("setting the back color to " + color.ToString)
  12.  
  13.         Me.BackColor = color
  14.  
  15.     End Sub
  16.  
  17.  
  18.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  19.  
  20.         reco.SetInputToDefaultAudioDevice()
  21.  
  22.         Dim gram As New Recognition.SrgsGrammar.SrgsDocument
  23.  
  24.         Dim colorRule As New Recognition.SrgsGrammar.SrgsRule("color")
  25.  
  26.         Dim colorsList As New Recognition.SrgsGrammar.SrgsOneOf("red", "green", "blue")
  27.  
  28.         colorRule.Add(colorsList)
  29.  
  30.         gram.Rules.Add(colorRule)
  31.  
  32.         gram.Root = colorRule
  33.  
  34.         reco.LoadGrammar(New Recognition.Grammar(gram))
  35.  
  36.         reco.RecognizeAsync()
  37.  
  38.     End Sub
  39.  
  40.     Private Sub reco_RecognizeCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted
  41.  
  42.         reco.RecognizeAsync()
  43.  
  44.     End Sub
  45.  
  46.     Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized
  47.  
  48.         Select Case e.Result.Text
  49.  
  50.             Case "red"
  51.  
  52.                 SetColor(Color.Red)
  53.  
  54.             Case "green"
  55.  
  56.                 SetColor(Color.Green)
  57.  
  58.             Case "blue"
  59.  
  60.                 SetColor(Color.Blue)
  61.  
  62.         End Select
  63.  
  64.     End Sub
  65.  
  66. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top