Advertisement
b_boy_ww

VB

Mar 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.21 KB | None | 0 0
  1. Imports System.Speech
  2. Imports System.Threading
  3. Imports System.Globalization
  4. Public Class Form1
  5.  
  6.     Public speechsynth As New Speech.Synthesis.SpeechSynthesizer
  7.     Dim Speech = CreateObject("SAPI.spvoice")
  8.     Public WithEvents recog As New Speech.Recognition.SpeechRecognitionEngine
  9.     Dim grammar As New System.Speech.Recognition.DictationGrammar()
  10.  
  11.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12.         Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB")
  13.         Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-GB")
  14.         recog.LoadGrammar(grammar)
  15.         recog.SetInputToDefaultAudioDevice()
  16.         recog.RecognizeAsync(Recognition.RecognizeMode.Multiple)
  17.     End Sub
  18.     Public Sub GotSpeech(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles recog.SpeechRecognized
  19.         Dim wordlist() As String
  20.         Dim entstring = e.Result.Text.ToLower()
  21.         wordlist = e.Result.Text.Split(" ")
  22.         CommandMgr(wordlist, entstring)
  23.     End Sub
  24.     Sub CommandMgr(ByRef wordlist(), ByVal entstring)
  25.         Dim cmdList() As String = {"test", "say", "null", "help", "death"}
  26.         For Each str As String In wordlist
  27.             str = str.ToLower()
  28.             ListBox1.Items.Add(str)
  29.             ListBox1.TopIndex = ListBox1.Items.Count - 1
  30.             If cmdList.Contains(str) Then
  31.                 Cmdexec(str, entstring, cmdList)
  32.             End If
  33.         Next
  34.     End Sub
  35.     Sub Cmdexec(ByVal str, ByVal entstring, ByVal cmds())
  36.         Select Case str
  37.             Case "test"
  38.                 Speech.speak("Test command activated")
  39.             Case "say"
  40.                 Speech.speak(entstring.remove(0, entstring.indexof("y") + 1))
  41.             Case "null"
  42.                 MessageBox.Show("Error 404 Null Not Found.", "404 ERROR", MessageBoxButtons.OK, MessageBoxIcon.Stop)
  43.             Case "help"
  44.                 Speech.speak("List of available commands")
  45.                 For Each cmd As String In cmds
  46.                     Speech.speak(cmd + ". ")
  47.                 Next
  48.             Case "death"
  49.                 Speech.speak("NANI")
  50.         End Select
  51.     End Sub
  52. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement