Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 28th, 2013  |  syntax: None  |  size: 3.61 KB  |  views: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Imports System.Speech
  2. Imports System.Speech.Recognition
  3.  
  4. Public Class Form1
  5.  
  6.     Dim x As String
  7.  
  8.     Dim WithEvents reco As New Recognition.SpeechRecognitionEngine
  9.  
  10.     Private Sub SetColor(ByVal color As System.Drawing.Color)
  11.  
  12.         Dim synth As New Synthesis.SpeechSynthesizer
  13.  
  14.         synth.SpeakAsync("Going to " + color.ToString + "in chrome")
  15.  
  16.         Me.BackColor = color
  17.  
  18.     End Sub
  19.  
  20.  
  21.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  22.  
  23.         reco.SetInputToDefaultAudioDevice()
  24.  
  25.         Dim gram As New Recognition.SrgsGrammar.SrgsDocument
  26.  
  27.         Dim colorRule As New Recognition.SrgsGrammar.SrgsRule("color")
  28.  
  29.         Dim OpenChrome As New Recognition.SrgsGrammar.SrgsOneOf("Brittney open chrome", "Brittney close chrome",
  30.                                                                 "Brittney open firefox", "Brittney close firefox",
  31.                                                                 "Brittney open internet explorer", "Brittney close internet explorer",
  32.                                                                 "Brittney open notepad", "Brittney close notepad",
  33.                                                                 "Brittney open paint", "Brittney close paint")
  34.  
  35.         colorRule.Add(OpenChrome)
  36.  
  37.         gram.Rules.Add(colorRule)
  38.  
  39.         gram.Root = colorRule
  40.  
  41.         reco.LoadGrammar(New Recognition.Grammar(gram))
  42.  
  43.         reco.RecognizeAsync()
  44.  
  45.     End Sub
  46.  
  47.     Private Sub reco_RecognizeCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted
  48.  
  49.         reco.RecognizeAsync()
  50.  
  51.     End Sub
  52.  
  53.     Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized
  54.  
  55.         Select Case e.Result.Text
  56.  
  57.             Case "Brittney open chrome"
  58.  
  59.                 System.Diagnostics.Process.Start("chrome.exe", "www.google.com")
  60.  
  61.             Case "Brittney open firefox"
  62.  
  63.                 System.Diagnostics.Process.Start("firefox.exe", "www.google.com")
  64.  
  65.             Case "Brittney close firefox"
  66.  
  67.                 Dim firefoxProcesses As Process() = Process.GetProcessesByName("firefox")
  68.  
  69.                 Array.ForEach(firefoxProcesses, Sub(p As Process) p.Kill())
  70.  
  71.             Case "Brittney close internet explorer"
  72.  
  73.                 Dim internetexplorerProcesses As Process() = Process.GetProcessesByName("iexplore")
  74.  
  75.                 Array.ForEach(internetexplorerProcesses, Sub(p As Process) p.Kill())
  76.  
  77.             Case "Brittney open internet explorer"
  78.  
  79.                 System.Diagnostics.Process.Start("iexplore.exe", "www.google.com")
  80.  
  81.  
  82.             Case "Brittney close chrome"
  83.  
  84.                 Dim chromeProcesses As Process() = Process.GetProcessesByName("chrome")
  85.  
  86.                 Array.ForEach(chromeProcesses, Sub(p As Process) p.Kill())
  87.  
  88.             Case "Brittney open notepad"
  89.  
  90.                 System.Diagnostics.Process.Start("notepad.exe")
  91.  
  92.  
  93.             Case "Brittney close notepad"
  94.  
  95.                 Dim notepadProcesses As Process() = Process.GetProcessesByName("notepad")
  96.  
  97.                 Array.ForEach(notepadProcesses, Sub(p As Process) p.Kill())
  98.  
  99.             Case "Brittney open paint"
  100.  
  101.                 System.Diagnostics.Process.Start("mspaint.exe")
  102.  
  103.             Case "Brittney close paint"
  104.  
  105.                 Dim paintProcesses As Process() = Process.GetProcessesByName("mspaint")
  106.  
  107.                 Array.ForEach(paintProcesses, Sub(p As Process) p.Kill())
  108.  
  109.         End Select
  110.  
  111.     End Sub
  112.  
  113. End Class
clone this paste RAW Paste Data