Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Speech
- Imports System.Threading
- Imports System.Globalization
- Public Class Form1
- Public speechsynth As New Speech.Synthesis.SpeechSynthesizer
- Dim Speech = CreateObject("SAPI.spvoice")
- Public WithEvents recog As New Speech.Recognition.SpeechRecognitionEngine
- Dim grammar As New System.Speech.Recognition.DictationGrammar()
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB")
- Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-GB")
- recog.LoadGrammar(grammar)
- recog.SetInputToDefaultAudioDevice()
- recog.RecognizeAsync(Recognition.RecognizeMode.Multiple)
- End Sub
- Public Sub GotSpeech(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles recog.SpeechRecognized
- Dim wordlist() As String
- Dim entstring = e.Result.Text.ToLower()
- wordlist = e.Result.Text.Split(" ")
- CommandMgr(wordlist, entstring)
- End Sub
- Sub CommandMgr(ByRef wordlist(), ByVal entstring)
- Dim cmdList() As String = {"test", "say", "null", "help", "death"}
- For Each str As String In wordlist
- str = str.ToLower()
- ListBox1.Items.Add(str)
- ListBox1.TopIndex = ListBox1.Items.Count - 1
- If cmdList.Contains(str) Then
- Cmdexec(str, entstring, cmdList)
- End If
- Next
- End Sub
- Sub Cmdexec(ByVal str, ByVal entstring, ByVal cmds())
- Select Case str
- Case "test"
- Speech.speak("Test command activated")
- Case "say"
- Speech.speak(entstring.remove(0, entstring.indexof("y") + 1))
- Case "null"
- MessageBox.Show("Error 404 Null Not Found.", "404 ERROR", MessageBoxButtons.OK, MessageBoxIcon.Stop)
- Case "help"
- Speech.speak("List of available commands")
- For Each cmd As String In cmds
- Speech.speak(cmd + ". ")
- Next
- Case "death"
- Speech.speak("NANI")
- End Select
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement