Saturday, September 21, 2013

Michael C's Custom J.A.R.V.I.S.

Michael C's Custom J.A.R.V.I.S.

               Hello, my name is Michael, as you've already seen from the title. Some time in March 2013 I was trying to find a J.A.R.V.I.S. - like application to go along with my Iron Man themed Rain meter skin. I soon realized there weren't many options out there aside from using Windows Speech Macros so I started to play around with the Windows Speech SDK and over time it turned into this J.A.R.V.I.S. project. I gave a demonstration video on YouTube just to show my creation but then I was getting a ton of requests for tutorials so I put up a few. As time went on I started to learn more and build upon the program. As of today my current tutorials contain some outdated (and let's just admit it, amateur methods). Down below is a provided list of requirements for the program to be able to run, updates/changes, and default commands you need to be aware of.

You can download the program here:
You can download the project folder here: (*Note: The project may not have all of the up to date features as the installer)


  • Windows Vista, Windows 7, Windows 8
  • Microphone (Built-in Mics usually don't work well)
  • .NET 4 Framework
  • Windows Speech Recognition set to ENGLISH: Go to Control Panel, Speech Recognition, Advanced Speech Options, and change Language to ENGLISH.

  • 9/17/2013
  • You can now check your Gmail account for new emails. The new commands for this feature are: (Check for new emails, Read the email, Open the email, Next email, Previous email, and Clear email list). Jarvis can only read the Sender, Subject, and Summary information. To read the entire email you must say, "Open the email". Each of these new commands can interrupt Jarvis from speaking. Ex: If he is reading a long email you can say, "Next email" and he will immediately move on. This interruption feature will be implemented to all commands soon.
  • 9/14/2013
  • You can change your Music and Video directories by saying "Change Music Directory" or "Change Video Directory", choosing a new directory and it will automatically update your libraries.
  • Saying "Refresh libraries" will reload all files within your music and video directories.
  • You can say "Stop listening" to keep Jarvis from listening and say "Jarvis Come Back Online" to get him to start listening. Or you can Click on the background image to make him start listening.
  • 9/10/2013
  • You can now choose between Celsius and Fahrenheit Temperatures.
  • 9/8/2013
  • You can now refer to songs by their Title and Band Name. Ex: "Play music", (Which song), "I Miss You by Blink-182". Note: If the song has a bad ID3 Tag (most likely pirated music) the program will refer to it by its file name instead.
  • 8/16/2013
  • The play music command supports .mp3, .m4a, and .wav file formats.
  • The play video command supports .mp4, .avi, and .mkv file formats.

  • 8/13/2013
  • Alarm Clock feature - Say "set the alarm", he will ask what time, then say the time. This feature is saved in the settings.
  • 8/11/2013
  • JARVIS loads all mp3/m4a file names in your My Music folder as well as all files in your My Videos folder into his Grammar. This allows you to say, "Play music", he will ask which song, you then say the file name and he will open it. Same goes for videos except you say "Play Video"
  • You no longer have to restart JARVIS to update commands. Just click Add and say Update Commands.
  • JARVIS should check if the grammar's were loaded properly and let you know if there is a missing element in your commands.
  • If JARVIS can't  connect to the Yahoo! Weather API, he will inform you.
  • 9/14/2013
  • Quicker start up time
  • Jarvis will no longer assume English is the default language so loading problems should be fixed. Although the default commands might not work as well in other languages. (Update coming)
  • Loading media directories and creating non existent text documents
  • 9/10/2013
  • Problems with saving User Info
  • 9/8/2013
  • Alarm clock - minValue cannot be greater than maxValue error
  • 8/16/2013
  • File check validation now implemented to prevent exceptions being thrown such as: ( 'one-of" must contain at least one ' item' element ) Hopefully this fixes the JIT runtime error.
  • 8/11/2013
  • Creating the JARVIS Custom Commands folder and txt files upon start up.

                                                                    Default Commands:

                                                                    • Hello
                                                                    • Hello Jarvis
                                                                    • Goodbye
                                                                    • Goodbye Jarvis
                                                                    • Close Jarvis
                                                                    • Jarvis
                                                                    • Stop talking
                                                                    • What's my name?
                                                                    • What time is it
                                                                    • What day is it
                                                                    • Whats todays date
                                                                    • Whats the date
                                                                    • Hows the weather
                                                                    • Whats the weather like
                                                                    • Whats it like outside
                                                                    • What will tomorrow be like
                                                                    • Whats tomorrows forecast
                                                                    • Whats tomorrow like
                                                                    • Whats the temperature
                                                                    • Whats the temperature outside
                                                                    • Play music
                                                                    • Play video
                                                                    • Switch Window
                                                                    • Close window
                                                                    • Out of the way
                                                                    • Come back
                                                                    • Show default commands
                                                                    • Show shell commands
                                                                    • Show web commands
                                                                    • Show social commands
                                                                    • Show Music Library
                                                                    • Show Video Library
                                                                    • Show Email List
                                                                    • Show listbox
                                                                    • Hide listbox
                                                                    • Shutdown
                                                                    • Log off
                                                                    • Restart
                                                                    • Abort
                                                                    • I want to add custom commands
                                                                    • I want to add a custom command
                                                                    • I want to add a command
                                                                    • Update commands
                                                                    • Set the alarm
                                                                    • What time is the alarm
                                                                    • Clear the alarm
                                                                    • Stop listening
                                                                    • JARVIS Come Back Online
                                                                    • Refresh libraries
                                                                    • Change video directory
                                                                    • Change music directory
                                                                    • Check for new emails
                                                                    • Read the email
                                                                    • Open the email
                                                                    • Next email
                                                                    • Previous email
                                                                    • Clear email list

                                                                    Monday, July 1, 2013

                                                                    JARVIS in C#

                                                                            SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
                                                                            SpeechSynthesizer JARVIS = new SpeechSynthesizer();
                                                                            string QEvent;
                                                                            string ProcWindow;
                                                                            double timer = 10;
                                                                            int count = 1;
                                                                            Random rnd = new Random();
                                                                            public Form1()

                                                                            private void Form1_Load(object sender, EventArgs e)
                                                                                _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"txt file location")))));
                                                                                _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
                                                                            void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
                                                                                int ranNum = rnd.Next(1, 10);
                                                                                string speech = e.Result.Text;
                                                                                switch (speech)
                                                                                    case "hello":
                                                                                    case "hello jarvis":
                                                                                        if (ranNum < 6) { JARVIS.Speak("Hello sir"); }
                                                                                        else if (ranNum > 5) { JARVIS.Speak("Hi"); }
                                                                                    case "goodbye":
                                                                                    case "goodbye jarvis":
                                                                                    case "close":
                                                                                    case "close jarvis":
                                                                                        JARVIS.Speak("Until next time");
                                                                                    case "jarvis":
                                                                                        if (ranNum < 5) { QEvent = ""; JARVIS.Speak("Yes sir"); }
                                                                                        else if (ranNum > 4) { QEvent = ""; JARVIS.Speak("Yes?"); }

                                                                                    case "open website":

                                                                                    //SHELL COMMANDS
                                                                                    case "open program":
                                                                                        System.Diagnostics.Process.Start("file location");

                                                                                    //CLOSE PROGRAMS
                                                                                    case "close program":
                                                                                        ProcWindow = "process name";

                                                                                    //CONDITION OF DAY
                                                                                    case "what time is it":
                                                                                        DateTime now = DateTime.Now;
                                                                                        string time = now.GetDateTimeFormats('t')[0];
                                                                                    case "what day is it":
                                                                                    case "whats the date":
                                                                                    case "whats todays date":

                                                                                    //OTHER COMMANDS
                                                                                    case "go fullscreen":
                                                                                        FormBorderStyle = FormBorderStyle.None;
                                                                                        WindowState = FormWindowState.Maximized;
                                                                                        TopMost = true;
                                                                                    case "exit fullscreen":
                                                                                        FormBorderStyle = FormBorderStyle.Sizable;
                                                                                        WindowState = FormWindowState.Normal;
                                                                                        TopMost = false;
                                                                                    case "switch window":
                                                                                        SendKeys.Send("%{TAB " + count + "}");
                                                                                        count += 1;
                                                                                    case "reset":
                                                                                        count = 1;
                                                                                        timer = 11;
                                                                                        lblTimer.Visible = false;
                                                                                        ShutdownTimer.Enabled = false;
                                                                                        lstCommands.Visible = false;
                                                                                    case "out of the way":
                                                                                        if (WindowState == FormWindowState.Normal || WindowState == FormWindowState.Maximized)
                                                                                            WindowState = FormWindowState.Minimized;
                                                                                            JARVIS.Speak("My apologies");
                                                                                    case "come back":
                                                                                        if (WindowState == FormWindowState.Minimized)
                                                                                            WindowState = FormWindowState.Normal;
                                                                                    case "show commands":
                                                                                        string[] commands = (File.ReadAllLines(@"txt file location"));
                                                                                        JARVIS.Speak("Very well");
                                                                                        lstCommands.SelectionMode = SelectionMode.None;
                                                                                        lstCommands.Visible = true;
                                                                                        foreach (string command in commands)
                                                                                    case "hide listbox":
                                                                                        lstCommands.Visible = false;

                                                                                    //SHUTDOWN RESTART LOG OFF
                                                                                    case "shutdown":
                                                                                        if (ShutdownTimer.Enabled == false)
                                                                                            QEvent = "shutdown";
                                                                                            JARVIS.Speak("I will shutdown shortly");
                                                                                            lblTimer.Visible = true;
                                                                                            ShutdownTimer.Enabled = true;
                                                                                    case "log off":
                                                                                        if (ShutdownTimer.Enabled == false)
                                                                                            QEvent = "logoff";
                                                                                            JARVIS.Speak("Logging off");
                                                                                            lblTimer.Visible = true;
                                                                                            ShutdownTimer.Enabled = true;
                                                                                    case "restart":
                                                                                        if (ShutdownTimer.Enabled == false)
                                                                                            QEvent = "restart";
                                                                                            JARVIS.Speak("I'll be back shortly");
                                                                                            lblTimer.Visible = true;
                                                                                            ShutdownTimer.Enabled = true;
                                                                                    case "abort":
                                                                                        if (ShutdownTimer.Enabled == true)
                                                                                            QEvent = "abort";
                                                                                    case "speed up":
                                                                                        if (ShutdownTimer.Enabled == true)
                                                                                            ShutdownTimer.Interval = ShutdownTimer.Interval / 10;
                                                                                    case "slow down":
                                                                                        if (ShutdownTimer.Enabled == true)
                                                                                            ShutdownTimer.Interval = ShutdownTimer.Interval * 10;
                                                                            private void ShutdownTimer_Tick(object sender, EventArgs e)
                                                                                if (timer == 0)
                                                                                    lblTimer.Visible = false;
                                                                                    ShutdownTimer.Enabled = false;
                                                                                else if (QEvent == "abort")
                                                                                    timer = 10;
                                                                                    lblTimer.Visible = false;
                                                                                    ShutdownTimer.Enabled = false;
                                                                                    timer = timer - .01;
                                                                                    lblTimer.Text = timer.ToString();
                                                                            private void ComputerTermination()
                                                                                switch (QEvent)
                                                                                    case "shutdown":
                                                                                        System.Diagnostics.Process.Start("shutdown", "-s");
                                                                                    case "logoff":
                                                                                        System.Diagnostics.Process.Start("shutdown", "-l");
                                                                                    case "restart":
                                                                                        System.Diagnostics.Process.Start("shutdown", "-r");
                                                                            private void StopWindow()
                                                                                System.Diagnostics.Process[] procs = System.Diagnostics.Process.GetProcessesByName(ProcWindow);
                                                                                foreach (System.Diagnostics.Process proc in procs)

                                                                    Thursday, May 30, 2013

                                                                    JARVIS Speech Recognition Program

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

                                                                    Public Class Form1
                                                                        '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

                                                                                Case Is = "HELLO JARVIS"
                                                                                    Jarvis.Speak("Hello sir")
                                                                                Case Is = "GOODBYE JARVIS"
                                                                                    Jarvis.Speak("Until next time")

                                                                                    '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"
                                                                                    Jarvis.Speak("Searching for local weather")

                                                                                    'SHELL COMMANDS
                                                                                Case Is = "RUN GOOGLE CHROME"
                                                                                    Jarvis.Speak("Right Away")
                                                                                Case Is = "RUN ITUNES"
                                                                                    Jarvis.speak("I'm in the mood for a bit of music actually")

                                                                                Case Is = "RUN FACEBOOK"
                                                                                Case Is = "RUN GOOGLE"
                                                                                Case Is = "RUN YAHOO"
                                                                                Case Is = "RUN PANDORA"
                                                                                Case Is = "RUN THE PIRATE BAY"
                                                                                Case Is = "RUN YOUTUBE"

                                                                                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"
                                                                                    Select Case Number
                                                                                        Case Is < 6
                                                                                            Jarvis.speak("My apologies sir")
                                                                                        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
                                                                                        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
                                                                                Case Is = "JARVIS"
                                                                                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"
                                                                                    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 sir?")
                                                                                            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
                                                                        End Sub

                                                                        'HIDES COMMANDS LIST BOX
                                                                        Private Sub lstboxCommands_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstboxCommands.SelectedIndexChanged
                                                                            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
                                                                                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

                                                                    End Class