Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27423

VS 2012 Need a little help with an error message

$
0
0
Hello there,
please don't kill me for asking, but I'm still very new to this.
What I'm trying to do is making an AI for my pc.
It has worked out surprisingly well until now.


Suddenly this message came and I haven't got a clue how to solve it. Hell I don't even know where to start looking.

An error occurred creating the form. See Exception.InnerException for details. The error is: 'phrase' cannot be an empty string.
Parameter name: phrase



Imports System.Speech.Recognition
Imports System.Speech.Recognition.SrgsGrammar
Imports System.Runtime.InteropServices 'For Monitor Command

Public Class JARVIS
'This object represents the Speech recognition engine
Private recognizer As SpeechRecognizer
Dim QuestionEvent As String

Public Sub New()

InitializeComponent() ' This call is required by the Windows Form Designer.

recognizer = New SpeechRecognizer() ' Add any initialization after the InitializeComponent() call.

AddHandler recognizer.SpeechDetected, AddressOf recognizer_SpeechDetected 'this event is raised when the user begins to speak

AddHandler recognizer.SpeechRecognitionRejected, AddressOf recognizer_SpeechRecognitionRejected 'this is raised when spoken words are not recognized as compliant to our grammar rules

AddHandler recognizer.SpeechRecognized, AddressOf recognizer_SpeechRecognized 'this is raised when the application correctly recognizes spoken words

Dim grammar As New GrammarBuilder()
grammar.Append(New Choices(System.IO.File.ReadAllLines("Commands.txt")))

recognizer.LoadGrammar(New Grammar(grammar))
End Sub

Private Sub recognizer_SpeechRecognized(ByVal sender As Object, ByVal e As SpeechRecognizedEventArgs)
Dim Random As New Random
Dim Number As Integer = Random.Next(1, 10)
Dim Jarvis = CreateObject("sapi.spvoice")
Select Case e.Result.Text.ToUpper

'GREETINGS

Case Is = "JARVIS ARE YOU THERE"
Jarvis.Speak("What can I do for you")
Case Is = "HELLO JARVIS"
Jarvis.Speak("Hello miss")
Case Is = "GOODBYE JARVIS"
Jarvis.Speak("Until next time")
Me.Close()

'DATE / TIME / WEATHER
Case Is = "WHAT TIME IS IT"
Jarvis.Speak(Format(Now, "Short Time"))
Case Is = "WHAT DAY IS IT"
Jarvis.Speak(Format(Now, "Long Date"))
Case Is = "HOWS THE WEATHER"
System.Diagnostics.Process.Start("https://www.google.com/webhp?sourceid=chrome-instant&ion=1&ie=UTF-8#output=search&sclient=psy-ab&q=weather&oq=&gs_l=&pbx=1&bav=on.2,or.r_cp.r_qf.&bvm=bv.47008514,d.eWU&fp=6c7f8a5fed4db490&biw=13 66&bih=643&ion=1&pf=p&pdl=300")
Jarvis.Speak("Searching for local weather")

'SHELL COMMANDS
Case Is = "RUN FIREFOX", "OPEN FIREFOX"
Jarvis.Speak("Right Away")
Shell("C:\Program Files (x86)\Mozilla Firefox\firefox.exe")
Case Is = "RUN ITUNES", "OPEN ITUNES", "PLAY SOME MUSIC"
Select Case Number
Case Is < 6
Jarvis.speak("I'm in the mood for a bit of music actually")
Case Is > 5
Jarvis.speak("You know, one day, you will ruin your hearing with all that noise")
End Select

Shell("C:\Program Files (x86)\iTunes\iTunes.exe")

Case Is = "RUN TOMB RAIDER"
If QuestionEvent = "Which Game" Or QuestionEvent = "Pick Game" Then
Shell("C:\Program Files (x86)\SQUARE ENIX\Tombraider\TombRaider.exe")
Else : Jarvis.Speak("Adding a bow has most definitely raised the value of this game.")
End If

'WEBSITES
Case Is = "RUN TUMBLR"
Jarvis.speak("Not again, haven't you got work to do?")
System.Diagnostics.Process.Start("http://www.tumblr.com")
Case Is = "OPEN MAIL"
Jarvis.speak("You do know, that you can check them on your phone too?")
System.Diagnostics.Process.Start("https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1374938343&rver=6.1.6206.0&wp=MBI&wreply=http:%2F%2Fmail.live.co m%2Fdefault.aspx&lc=1031&id=64855&mkt=de-de&cbcxt=mai&snsc=1")
Case Is = "RUN GOOGLE"
System.Diagnostics.Process.Start("http://www.google.com")
Case Is = "RUN THE PIRATE BAY"
System.Diagnostics.Process.Start("http://www.thepiratebay.se")
Case Is = "OPEN YOUTUBE", "SHOW ME VIDEOS"
System.Diagnostics.Process.Start("http://www.youtube.com")

'MISCELLANEOUS
Case Is = "SHOW COMMANDS"
lstboxCommands.Visible = True
Jarvis.speak("Here we are")
Case Is = "HIDE COMMANDS"
lstboxCommands.Visible = False
Jarvis.speak("Very well")
Case Is = "OUT OF THE WAY JARVIS", "OUT OF THE WAY", "BACK OFF", "JARVIS OUT OF THE WAY"
Select Case Number
Case Is < 6
Jarvis.speak("My apologies miss")
Case Is > 5
Jarvis.speak("Right away")
End Select
Me.WindowState = FormWindowState.Minimized
Case Is = "COME BACK JARVIS", "COME BACK"
Me.WindowState = FormWindowState.Normal

Jarvis.speak("Here I am")
Case Is = "OPEN DISK DRIVE"
Dim oWMP = CreateObject("WMPlayer.OCX.7")
Dim CDROM = oWMP.cdromCollection
If CDROM.Count = 2 Then
CDROM.Item(1).Eject()
Jarvis.speak("Its now open")
End If
Case Is = "MONITOR OFF"
SendMessage(Me.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 2)
Jarvis.Speak("I'll just close my eyes for a minute")
Case Is = "SHUTDOWN"
QuestionEvent = "Shutdown"
Timer1.Enabled = True
lblTimer.Visible = True
Case Is = "RESTART"
QuestionEvent = "Restart"
Timer1.Enabled = True
lblTimer.Visible = True
Case Is = "LOG OFF"
QuestionEvent = "Log Off"
Timer1.Enabled = True
lblTimer.Visible = True
Case Is = "ABORT"
Timer1.Enabled = False
lblTimer.Visible = False

QuestionEvent = String.Empty
Case Is = "SPEED UP"
If Timer1.Interval = 1 Then
Jarvis.Speak("Performing at maximum capacity")
Else : Timer1.Interval = Timer1.Interval / 10
End If
Case Is = "SLOW DOWN"
If Timer1.Interval = 1000 Then
Jarvis.Speak("If it were any slower it would be standing still")
Else : Timer1.Interval = Timer1.Interval * 10

End If
'QUESTION / EVENTS
Case Is = "PLAY A GAME", "LAUNCH A GAME", "I'M IN THE MOOD TO PLAY"
Jarvis.speak("Which game shall I start miss?")
QuestionEvent = "Which Game"
Case Is = "What Games are available"
If QuestionEvent = "Which Game" Then
Jarvis.Speak("Tomb Raider only at the moment.")
QuestionEvent = "Pick Game"
ElseIf QuestionEvent = "Pick Game" Then
Jarvis.speak("I just told you miss. Tombraider is the only one.")
Else : Jarvis.Speak("Ah! Though I'm sure you got more important things to do, would you like to start a game?")
QuestionEvent = "Yes or no for Game"
End If

'SOCIAL
Case Is = "YES"
If QuestionEvent = "Yes or No for Game" Then
Jarvis.Speak("I have Tombraider for you.")
QuestionEvent = "Pick Game"
Else : Jarvis.speak("I'm not sure what you're referring to")
End If
Case Is = "JARVIS"
Jarvis.speak("Yes?")
Case Is = "GOOD", "IM GOOD"
Select Case QuestionEvent
Case Is = "Particularly well"
Jarvis.speak("Glad to hear it")
Case Is = "I'm good"
Jarvis.speak("Of course")
Case Is = "And you"
Jarvis.speak("Good")
End Select
Case Is = "HOW ARE YOU", "HOW ARE YOU DOING", "HOW ARE YOU TODAY", "HOWS LIFE"
Select Case Number
Case Is = 1, 2
Jarvis.speak("Good as always. Thanks for asking")
Case Is = 3, 4
Jarvis.speak("I'm doing particularly well actually. How are you?")
QuestionEvent = "Particularly well"
Case Is = 5, 6
Jarvis.speak("I'm good. How about you miss?")
QuestionEvent = "I'm good"
Case Else : Jarvis.speak("Couldn't be better. And you?")
QuestionEvent = "And you"
End Select
End Select
End Sub

'LABEL DETECT / REJECT
Private Sub recognizer_SpeechDetected(ByVal sender As Object, ByVal e As SpeechDetectedEventArgs)

Label1.ForeColor = Color.Green : Label1.BackColor = Color.Transparent : Label1.Text = "Speech engine has detected that you spoke something"
End Sub
Private Sub recognizer_SpeechRecognitionRejected(ByVal sender As Object, ByVal e As SpeechRecognitionRejectedEventArgs)

Label1.ForeColor = Color.Red : Label1.BackColor = Color.Transparent : Label1.Text = ("Sorry, but the phrase could not be recognized")

End Sub

'LOADS THE COMMANDS INTO AN ARRAY AND LISTBOX
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Commands() As String = System.IO.File.ReadAllLines("Commands.txt")
For i As Integer = 0 To Commands.Count - 1
lstboxCommands.Items.Add(Commands(i))
Next
End Sub

'HIDES COMMANDS LIST BOX
Private Sub lstboxCommands_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
lstboxCommands.Visible = False
End Sub

'FOR MONITOR COMMAND
Public WM_SYSCOMMAND As Integer = &H112
Public SC_MONITORPOWER As Integer = &HF170
<DllImport("user32.dll")> _
Private Shared Function SendMessage(ByVal hWnd As Integer, ByVal hMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lblTimer.Text = FormatNumber(Val(lblTimer.Text) - Val(0.01), 2)
If lblTimer.Text = 0 Then
ShutdownProcedure()
Timer1.Enabled = False
lblTimer.Visible = False
End If
End Sub

Sub ShutdownProcedure()
If QuestionEvent = "Shutdown" Then
System.Diagnostics.Process.Start("shutdown", "-s")
ElseIf QuestionEvent = "Restart" Then
System.Diagnostics.Process.Start("shutdown", "-r")
ElseIf QuestionEvent = "Log Off" Then
System.Diagnostics.Process.Start("shutdown", "-l")
End If

End Sub

Private Sub Label1_Click(sender As Object, e As EventArgs)
Dim Commands() As String = System.IO.File.ReadLines("Commands.txt")
For i As Integer = 0 To Commands.Count - 1
lstboxCommands.Items.Add(Commands(i))
Next
End Sub

Private Sub lblTimer_Click(sender As Object, e As EventArgs)

End Sub
End Class



Please help me, I'm truely at my wits end.
Lots of love,
Cornelia

Viewing all articles
Browse latest Browse all 27423

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>