1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
Imports System.Globalization Imports System.Speech Imports System.Speech.Recognition Imports System.Speech.Synthesis Module Module1 Dim ss As New SpeechSynthesizer() Dim sre As SpeechRecognitionEngine Dim done As Boolean = False Dim speechOn As Boolean = True Public Sub Main() ss.SetOutputToDefaultAudioDevice() ss.Speak("Starting") Dim ci As New CultureInfo("en-us") sre = New SpeechRecognitionEngine(ci) sre.SetInputToDefaultAudioDevice() AddHandler sre.SpeechRecognized, AddressOf sre_SpeechRecognized LoadGrammer() sre.RecognizeAsync(RecognizeMode.Multiple) While done = False End While Try Console.WriteLine(vbLf & "Hit <enter> to close shell" & vbLf) Console.ReadLine() Catch ex As Exception Console.WriteLine(ex.Message) Console.ReadLine() End Try End Sub Private Function LoadGrammer() Try Dim ch_StartStopCommands As New Choices() ch_StartStopCommands.Add("rdp") ch_StartStopCommands.Add("speech on") ch_StartStopCommands.Add("speech off") ch_StartStopCommands.Add("Close") Dim gb_StartStop As New GrammarBuilder() gb_StartStop.Append(ch_StartStopCommands) Dim g_StartStop As New Grammar(gb_StartStop) sre.LoadGrammarAsync(g_StartStop) Dim ch_boolean As New Choices() ch_boolean.Add("dictate on") ch_boolean.Add("dictate off") ch_boolean.Add("dictation on") ch_boolean.Add("dictation off") Dim gb_dictate As New GrammarBuilder() gb_dictate.Append(ch_boolean) Dim g_dictate As New Grammar(gb_dictate) sre.LoadGrammarAsync(g_dictate) Dim ch_Numbers As New Choices() ch_Numbers.Add("1") ch_Numbers.Add("2") ch_Numbers.Add("3") ch_Numbers.Add("4") Dim gb_WhatIsXplusY As New GrammarBuilder() gb_WhatIsXplusY.Append("What Is") gb_WhatIsXplusY.Append(ch_Numbers) gb_WhatIsXplusY.Append("plus") gb_WhatIsXplusY.Append(ch_Numbers) Dim g_WhatIsXplusY As New Grammar(gb_WhatIsXplusY) sre.LoadGrammarAsync(g_WhatIsXplusY) Dim ch_servers As New Choices() ch_servers.Add("fileshare users") ch_servers.Add("provision") ch_servers.Add("vmServer") ch_servers.Add("file eye es people") Dim explorerGrammerBuilder As New GrammarBuilder() explorerGrammerBuilder.Append("explorer") explorerGrammerBuilder.Append(ch_servers) Dim explorerGrammer As New Grammar(explorerGrammerBuilder) sre.LoadGrammarAsync(explorerGrammer) Dim ch_apps As New Choices({"notepad", "hexeditor", "datacenter", "prtg", "cacti", "nagios", "eye es portal", "infoblox", "command"}) Dim openGrammerBuilder As New GrammarBuilder() openGrammerBuilder.Append("open") openGrammerBuilder.Append(ch_apps) Dim openGrammer As New Grammar(openGrammerBuilder) sre.LoadGrammarAsync(openGrammer) Dim ch_rdp As New Choices({"vm", "nt"}) Dim ch_hundres As New Choices({"1", "2", "3", "4", "5", "6", "7", "8", "9", "100", "200", "300", "400", "500", "600", "700", "800", "900"}) Dim ch_tens As New Choices({"1", "2", "3", "4", "5", "6", "7", "8", "9", "eleven", "twelve", "thirteen", "fourteen", "fifthteen", "sixten", "seventeen", "eightteen", "nineteen", "20", "30", "40", "50", "60", "70", "80", "90"}) Dim ch_ones As New Choices({"1", "2", "3", "4", "5", "6", "7", "8", "9"}) Dim rdpGrammerBuilder As New GrammarBuilder() rdpGrammerBuilder.Append("rdp") rdpGrammerBuilder.Append(ch_rdp) rdpGrammerBuilder.Append(ch_hundres) rdpGrammerBuilder.Append(ch_tens) rdpGrammerBuilder.Append(ch_ones, 0, 1) 'rdpGrammerBuilder.AppendDictation("spelling") Dim rdpGrammer As New Grammar(rdpGrammerBuilder) sre.LoadGrammarAsync(rdpGrammer) Dim ch_drive As New Choices({"C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"}) Dim TreeSizeGrammerBuilder As New GrammarBuilder() TreeSizeGrammerBuilder.Append("treesize") TreeSizeGrammerBuilder.Append(ch_rdp) TreeSizeGrammerBuilder.Append(ch_hundres) TreeSizeGrammerBuilder.Append(ch_tens) TreeSizeGrammerBuilder.Append(ch_ones, 0, 1) TreeSizeGrammerBuilder.Append(ch_drive, 0, 1) 'rdpGrammerBuilder.AppendDictation("spelling") Dim TreeSizeGrammer As New Grammar(TreeSizeGrammerBuilder) sre.LoadGrammarAsync(TreeSizeGrammer) Catch ex As Exception Console.WriteLine(ex.Message) Console.ReadLine() End Try End Function Public Function URLDecode(ByVal Source As String) As String Dim x As Integer = 0 Dim CharVal As Byte = 0 Dim sb As New System.Text.StringBuilder() For x = 0 To (Source.Length - 1) Dim c As Char = Source(x) 'Check for space If (c = "+") Then sb.Append(" ") ElseIf c <> "%" Then 'Not hex value so add the chars to string builder. sb.Append(c) Else 'Convert hex value to char value. CharVal = Int("&H" & Source(x + 1) & Source(x + 2)) 'Add the chars to string builder. sb.Append(Chr(CharVal)) 'INC by 2 x += 2 End If Next 'Return the string. Return sb.ToString() End Function ' Main WithEvents DictationRecognition As SpeechRecognitionEngine Dim IsDicatating As Boolean = False Private Sub sre_SpeechRecognized(sender As Object, e As SpeechRecognizedEventArgs) Dim txt As String = e.Result.Text Dim confidence As Single = e.Result.Confidence Console.WriteLine(Convert.ToString(vbLf & "Recognized: ") & txt) If confidence < 0.7 Then Return End If If txt.IndexOf("dictat") >= 0 Then Dim words As String() = txt.Split(" "c) Select Case words(1) Case "on" IsDicatating = True sre.UnloadAllGrammars() Dim ch_StartStopCommands As New Choices() ch_StartStopCommands.Add("dictate off") Dim gb_StartStop As New GrammarBuilder() gb_StartStop.Append(ch_StartStopCommands) Dim g_StartStop As New Grammar(gb_StartStop) 'sre.LoadGrammarAsync(g_StartStop) DictationRecognition = New SpeechRecognitionEngine(New System.Globalization.CultureInfo("en-US")) Dim dg As New DictationGrammar("grammar:dictation") dg.Name = "default dictation" dg.Enabled = True DictationRecognition.LoadGrammar(dg) DictationRecognition.SetInputToDefaultAudioDevice() DictationRecognition.RecognizeAsync(RecognizeMode.Multiple) Case "off" If IsDicatating Then DictationRecognition.UnloadAllGrammars() DictationRecognition.Dispose() LoadGrammer() IsDicatating = False Else Return End If End Select End If If txt.IndexOf("explorer") >= 0 Then Dim words As String() = txt.Split(" "c) Select Case words(1) Case "provision" Process.Start("\\vmServer\c$\Program Files\proVision") End Select End If If txt.IndexOf("open") >= 0 Then Dim words As String() = txt.Split(" "c) Select Case words(1) Case "notepad" Process.Start("notepad++") Case "datacenter" Process.Start("https://mydatacenter/") Case "prtg" Process.Start("https://prtg/") Case "nagios" Process.Start("https://nagios/") Case "cacti" Process.Start("https://cacti") Case "eye es portal" Process.Start("https://isportal/") Case "infoblox" Process.Start("https://infoblox/ui/") Case "command" Process.Start("cmd") End Select End If If txt.IndexOf("rdp") >= 0 Then Dim words As String() = txt.Split(" "c) If words.Length = 5 Then words(3) = words(3).Substring(0, 1) & words(4) End If Dim MyCreated As String = "mstsc /v:" & words(1) & words(2) & words(3) & " /f" Process.Start("mstsc", "/v:" & words(1) & words(2) & words(3) & " /f") End If If txt.IndexOf("treesize") >= 0 Then Dim words As String() = txt.Split(" "c) If words.Length = 6 Then words(3) = words(3).Substring(0, 1) & words(4) Process.Start("C:\Program Files\JAM Software\TreeSize Professional\TreeSize.exe", "\\" & words(1) & words(2) & words(3) & "\" & words(5) & "$") Else Process.Start("C:\Program Files\JAM Software\TreeSize Professional\TreeSize.exe", "\\" & words(1) & words(2) & words(3) & "\" & words(4) & "$") End If End If If txt.IndexOf("speech on") >= 0 Then Console.WriteLine("Speech Is now ON") speechOn = True End If If txt.IndexOf("speech off") >= 0 Then Console.WriteLine("Speech Is now OFF") speechOn = False End If If speechOn = False Then Return End If If txt.IndexOf("klatu") >= 0 AndAlso txt.IndexOf("barada") >= 0 Then DirectCast(sender, SpeechRecognitionEngine).RecognizeAsyncCancel() done = True Console.WriteLine("(Speaking: Farewell)") ss.Speak("Farewell") End If If txt.IndexOf("What") >= 0 AndAlso txt.IndexOf("plus") >= 0 Then Dim words As String() = txt.Split(" "c) Dim num1 As Integer = Integer.Parse(words(2)) Dim num2 As Integer = Integer.Parse(words(4)) Dim sum As Integer = num1 + num2 Console.WriteLine("Test") Console.WriteLine("Speaking: " & words(2) & " plus " & words(4) & " equals " & sum & ")") ss.SpeakAsync(words(2) & " plus " & words(4) & " equals " & sum) End If End Sub Private Sub DictationRecognition_SpeechRecognized(sender As Object, e As SpeechRecognizedEventArgs) Handles DictationRecognition.SpeechRecognized Debug.WriteLine("SpeechRecognized: " & e.Result.Confidence & " - " & e.Result.Text) If e.Result.Confidence > 0.55 Then System.Windows.Forms.SendKeys.SendWait(e.Result.Text) End If End Sub Private Sub DictationRecognition_SpeechDetected(sender As Object, e As SpeechDetectedEventArgs) Handles DictationRecognition.SpeechDetected Debug.WriteLine("SpeechDetected: " & e.AudioPosition.Seconds) End Sub Private Sub DictationRecognition_RecognizeCompleted(sender As Object, e As RecognizeCompletedEventArgs) Handles DictationRecognition.RecognizeCompleted Debug.WriteLine("RecognizeCompleted: " & e.Result.Confidence & " - " & e.Result.Text) End Sub Private Sub DictationRecognition_SpeechHypothesized(sender As Object, e As SpeechHypothesizedEventArgs) Handles DictationRecognition.SpeechHypothesized Debug.WriteLine("SpeechHypothesized: " & e.Result.Confidence & e.Result.Text) End Sub Private Sub DictationRecognition_SpeechRecognitionRejected(sender As Object, e As SpeechRecognitionRejectedEventArgs) Handles DictationRecognition.SpeechRecognitionRejected Debug.WriteLine("SpeechRecognitionRejected: " & e.Result.Text) End Sub Private Sub DictationRecognition_LoadGrammarCompleted(sender As Object, e As LoadGrammarCompletedEventArgs) Handles DictationRecognition.LoadGrammarCompleted Debug.WriteLine("Grammer Completed: " & e.Grammar.Name) End Sub End Module |