Advertisement
Guest User

code (shortened)

a guest
Feb 1st, 2014
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. Imports System.Speech.Recognition
  2. Imports System.Speech.Recognition.SrgsGrammar
  3.  
  4. Public Class Form1
  5.  
  6. Private recognizer As SpeechRecognizer
  7.  
  8. Public Sub New()
  9.  
  10. ' This call is required by the designer.
  11. InitializeComponent()
  12.  
  13. recognizer = New SpeechRecognizer()
  14.  
  15. ' Add any initialization after the InitializeComponent() call.
  16.  
  17. AddHandler recognizer.SpeechDetected, AddressOf recognizer_SpeechDetected
  18.  
  19. AddHandler recognizer.SpeechRecognitionRejected, AddressOf recognizer_SpeechRecognitionRejected
  20.  
  21. AddHandler recognizer.SpeechRecognized, AddressOf recognizer_SpeechRecognized
  22.  
  23. Dim grammar As New GrammarBuilder()
  24. grammar.Append(New Choices("queue", "tag", "draft"))
  25. grammar.Append(New Choices("madoka", "kill la kill", "kyoukai no kanata", "back", " "))
  26.  
  27. recognizer.LoadGrammar(New Grammar(grammar))
  28. End Sub
  29.  
  30. Private Sub recognizer_SpeechRecognized(ByVal sender As Object, ByVal e As SpeechRecognizedEventArgs)
  31.  
  32. Select Case e.Result.Text.ToUpper
  33.  
  34. Case Is = "tag madoka"
  35. AppActivate("chrome.exe")
  36. SendKeys.Send("t")
  37. SendKeys.Send("pmmm")
  38. SendKeys.Send("{TAB}{TAB}")
  39. SendKeys.Send("r")
  40.  
  41. Case Is = "tag kill la kill"
  42. SendKeys.Send("t")
  43. SendKeys.Send("klk")
  44. SendKeys.Send("{TAB}{TAB}")
  45. SendKeys.Send("r")
  46.  
  47. Case Is = "tag kyoukai no kanata"
  48. SendKeys.Send("t")
  49. SendKeys.Send("knk")
  50. SendKeys.Send("{TAB}{TAB}")
  51. SendKeys.Send("r")
  52.  
  53. Case Is = "draft madoka"
  54. SendKeys.Send("t")
  55. SendKeys.Send("pmmm")
  56. SendKeys.Send("{TAB}{TAB}")
  57. SendKeys.Send("d")
  58.  
  59. Case Is = "draft kill la kill"
  60. SendKeys.Send("t")
  61. SendKeys.Send("klk")
  62. SendKeys.Send("{TAB}{TAB}")
  63. SendKeys.Send("d")
  64.  
  65. Case Is = "draft kyoukai no kanata"
  66. SendKeys.Send("t")
  67. SendKeys.Send("knk")
  68. SendKeys.Send("{TAB}{TAB}")
  69. SendKeys.Send("d")
  70.  
  71. Case Is = "queue madoka"
  72. SendKeys.Send("t")
  73. SendKeys.Send("pmmm")
  74. SendKeys.Send("{TAB}{TAB}")
  75. SendKeys.Send("q")
  76.  
  77. Case Is = "queue kill la kill"
  78. SendKeys.Send("t")
  79. SendKeys.Send("klk")
  80. SendKeys.Send("{TAB}{TAB}")
  81. SendKeys.Send("q")
  82.  
  83. Case Is = "queue kyoukai no kanata"
  84. SendKeys.Send("t")
  85. SendKeys.Send("knk")
  86. SendKeys.Send("{TAB}{TAB}")
  87. SendKeys.Send("q")
  88.  
  89. Case Is = "back"
  90. SendKeys.Send("k")
  91.  
  92. End Select
  93. End Sub
  94. Dim speaking As Boolean
  95.  
  96. Private Function CheckIfSpeaking() As Boolean
  97. If speaking = False Then
  98. Threading.Thread.Sleep(2000)
  99. SendKeys.Send("j")
  100. Return True
  101. Else
  102. Return False
  103. End If
  104. End Function
  105. Private Sub recognizer_SpeechDetected(ByVal sender As Object, ByVal e As SpeechDetectedEventArgs)
  106. speaking = True
  107. End Sub
  108.  
  109. Private Sub recognizer_SpeechRecognitionRejected(ByVal sender As Object, ByVal e As SpeechRecognitionRejectedEventArgs)
  110. speaking = False
  111. End Sub
  112. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement