Skip to content

Instantly share code, notes, and snippets.

@ezesundayeze
Created September 2, 2016 13:06
Show Gist options
  • Save ezesundayeze/99e431cca6db991cb0992fc6e90c79f6 to your computer and use it in GitHub Desktop.
Save ezesundayeze/99e431cca6db991cb0992fc6e90c79f6 to your computer and use it in GitHub Desktop.
Imports System.Speech
Public Class Form1
Dim WithEvents reco As New Recognition.SpeechRecognitionEngine
Dim s As New Process
Private Sub shutdown()
Dim syn As New Synthesis.SpeechSynthesizer
syn.SpeakAsync("I called Shutdown")
System.Diagnostics.Process.Start("shutdown", "-s -t 00")
Me.Close()
End Sub
Private Sub restart()
Dim syn As New Synthesis.SpeechSynthesizer
syn.SpeakAsync("I called restart") '??C C?EE C???E C?I? ??E??? E?I?C E??? C?E C?C?? ??C? C?EE ?C????
Shell("shutdown -r")
Me.Close()
End Sub
Private Sub Setcolor(ByVal color As System.Drawing.Color)
Dim syn As New Synthesis.SpeechSynthesizer
syn.SpeakAsync("walid selected color " + color.ToString)
Me.BackColor = color
End Sub
Dim vl As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
On Error Resume Next
reco.SetInputToDefaultAudioDevice()
Dim gram As New Recognition.SrgsGrammar.SrgsDocument
Dim colorRule As New Recognition.SrgsGrammar.SrgsRule("name")
Dim colorList As New Recognition.SrgsGrammar.SrgsOneOf("shutdown", "restart", "Edit Microsoft Word Document", "open Microsoft Word Document", "Save word", "yellow", "white")
colorRule.Add(colorList)
gram.Rules.Add(colorRule)
gram.Root = colorRule
reco.LoadGrammar(New Recognition.Grammar(gram))
reco.RecognizeAsync()
End Sub
Private Sub recog(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted
reco.RecognizeAsync()
TextBox1.Text = reco.Grammars.Count - 1
End Sub
Private Sub open()
Dim syn As New Synthesis.SpeechSynthesizer
syn.SpeakAsync("Open microsoft word document") ' ?IC C???I ??I ????
Process.Start(My.Computer.FileSystem.SpecialDirectories.Desktop & "\New Microsoft Word Document.docx")
End Sub
Private Sub write()
Dim syn As New Synthesis.SpeechSynthesizer
syn.SpeakAsync("edit microsoft word document") ' ?IC C???I ??I ????
TextBox1.Text = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\New Microsoft Word Document.docx")
End Sub
Private Sub save()
Dim syn As New Synthesis.SpeechSynthesizer
syn.SpeakAsync("save microsoft word document") ' ?IC C???I ??I ????
End Sub
Sub speech_recog(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized
TextBox1.Text = e.Result.Text
'"Shutdown", "open Microsoft Word Document", "Edit Microsoft Word Document", "Save word", "restart", "Good", "know", "please", "hi", "morning", "today" why you write this?
Select Case e.Result.Text
Case "Shutdown"
shutdown()
Case "open Microsoft Word Document"
open()
Case "Edit Microsoft Word Document"
write()
Case "Save word"
save()
Case "restart"
restart()
Case "white"
Setcolor(Color.White)
Case "yellow"
Setcolor(Color.Yellow)
End Select
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment