Making Speech Recognition Mod :)

I Had A Request That "How To Use Speech Recognition In My Mod?"


So Here We go:





Open Your Project Add Refrences : System.Speech



And Write As I Do :


These Were My USING Codes :P

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using GTA;
using System.Runtime.InteropServices;

igonre those 1 and 2 if you see them


And Now In Public Class:


private SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
        private SpeechSynthesizer JARVIS = new SpeechSynthesizer();

        private string currentFunction;

And Now the Public OF That Class:


Tick += FunctionCaller;
            Game.Console.Print("Working!");
            Game.DisplayText("We Are Ready To Go Sir");
            recognizer.SetInputToDefaultAudioDevice();
            recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Program Files\JARIVS MOD\JARVIS.txt")))));->ChangeableDirectory
            recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(RecognizerSpeechRecognized);
            recognizer.RecognizeAsync(RecognizeMode.Multiple);


Now The Voids :)     :


private void FunctionCaller(object sender, EventArgs e)
        {
            switch (currentFunction)
            {
                case "Reload":
                    Game.LocalPlayer.Character.Weapons.Current.AmmoInClip = Game.LocalPlayer.Character.Weapons.Current.MaxAmmoInClip;
                    currentFunction = null;
                    break;
                case "Helicopter":
                    Vector3 hPos = Player.Character.Position.Around(10.0f);
                    World.CreateVehicle(new Model("ANNIHILATOR"), hPos);
                    currentFunction = null;
                    break;
                case "Sports Car":
                    Vector3 scpos = Player.Character.Position.Around(10.0f);
                    World.CreateVehicle(new Model("SUPERGT"), scpos);
                    currentFunction = null;
                    break;
                case "Bike":
                    Vector3 zpos = Player.Character.Position.Around(10.0f);
                    World.CreateVehicle(new Model("NRG900"), zpos);
                    currentFunction = null;
                    break;
                case "Dont Leave Me Alone":
                case "Increase wanted level":
                    Player.WantedLevel++;
                    currentFunction = null;
                    break;

                case "Leave Me Alone":
                case "Decrease wanted level":
                    Player.WantedLevel--;
                    currentFunction = null;
                    break;
                case "Give Me Some Money":
                    Player.Money++;
                    currentFunction = null;
                    break;
                case "Normal Car":
                    Vector3 ncpos = Player.Character.Position.Around(10.0f);
                    World.CreateVehicle(new Model("ADMIRAL"), ncpos);
                    currentFunction = null;
                    break;
                case "Heal Me":
                    Player.Character.Health = 100;
                    Player.Character.Armor = 100;
                    break;
            }
        }

        private void RecognizerSpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            currentFunction = e.Result.Text;
            switch (currentFunction)
            {
                //Commands
                case "Reload":
                    JARVIS.Speak("Checking Ammo. Reloading Gun");
                    break;
                case "Helicopter":
                    JARVIS.Speak("Okay Sir");
                    break;
                case "Sports Car":
                    JARVIS.Speak("You May Drive Fast Sir.");
                    break;
                case "Jarvis":
                    JARVIS.Speak("May I Do Some Moding Sir?");
                    break;
                case "Which game Is This":
                case "What game is this":
                case "Game Name Please":
                    JARVIS.Speak("Sir Its Grand Theft Auto 4");
                    break;
                case "A Car":
                    JARVIS.Speak("Sports Car Or Normal Car?");
                    break;
                case "Bike":
                    JARVIS.Speak("As You Wish Sir");
                    break;
                 case "Dont Leave Me Alone":
                case "Increase wanted level":
                    JARVIS.Speak("Giving You Company Sir");
                    break;
                case "Leave Me Alone":
                case "Decrease wanted level":
                    JARVIS.Speak("Bye Cops Dont Need You Anymore");
                    break;
                case "Give Me Some Money":
                    JARVIS.Speak("Hacking Bank Of Liberty City");
                    break;
                case "Normal Car":
                    JARVIS.Speak("Drive Normally Sir");
                    break;
                case "Heal Me":
                    JARVIS.Speak("Healing You. You Are Healthy Now");
                    break;
            }

        }

Enjoy
Until Next Time :D


Project File: http://www.4shared.com/rar/E0K-v_bTce/Alex_Gta_4.html?











      1 comment: