Advertisement
Rugz007

Speech Recognition Mod BETA

May 21st, 2014
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Speech.Recognition;
  10. using System.Speech.Synthesis;
  11. using System.Threading;
  12. using System.Xml.Linq;
  13. using System.Xml;
  14. using System.IO;
  15. using GTA;
  16.  
  17. namespace Speech_Recognizer
  18. {
  19.     public class Form1 : Script
  20.     {
  21.         private SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine();
  22.         private SpeechSynthesizer JARVIS = new SpeechSynthesizer();
  23.  
  24.         private string currentFunction;
  25.  
  26.         public Form1()
  27.         {
  28.             Tick += FunctionCaller;
  29.             Game.Console.Print("Working!");
  30.  
  31.             recognizer.SetInputToDefaultAudioDevice();
  32.             recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Program Files\Alex SR program\Alex.txt")))));
  33.             recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(RecognizerSpeechRecognized);
  34.             recognizer.RecognizeAsync(RecognizeMode.Multiple);
  35.         }
  36.  
  37.         private void FunctionCaller(object sender, EventArgs e)
  38.         {
  39.             switch (currentFunction)
  40.             {
  41.                 case "Reload":
  42.                     //insert code to reload
  43.                     currentFunction = null;
  44.                     break;
  45.                 case "Helicopter":
  46.                     Vector3 hPos = Player.Character.Position.Around(10.0f);
  47.                     World.CreateVehicle(new Model("ANNIHILATOR"), hPos);
  48.                     currentFunction = null;
  49.                     break;
  50.                 case "Sports Car":
  51.                     Vector3 scpos = Player.Character.Position.Around(10.0f);
  52.                     World.CreateVehicle(new Model("COMET"), scpos);
  53.                     currentFunction = null;
  54.                     break;
  55.                 case "Bike":
  56.                     Vector3 zpos = Player.Character.Position.Around(10.0f);
  57.                     World.CreateVehicle(new Model("NRG900"), zpos);
  58.                     currentFunction = null;
  59.                     break;
  60.                 case "Dont Leave Me Alone":
  61.                 case "Increase wanted level":
  62.                     Player.WantedLevel++;
  63.                     currentFunction = null;
  64.                     break;
  65.  
  66.                 case "Leave Me Alone":
  67.                 case "Decrease wanted level":
  68.                     Player.WantedLevel--;
  69.                     currentFunction = null;
  70.                     break;
  71.  
  72.  
  73.             }
  74.         }
  75.  
  76.         private void RecognizerSpeechRecognized(object sender, SpeechRecognizedEventArgs e)
  77.         {
  78.             currentFunction = e.Result.Text;
  79.             switch (currentFunction)
  80.             {
  81.                 //Commands
  82.                 case "Reload":
  83.                     JARVIS.Speak("Checking Ammo. Reloading Gun");
  84.                     break;
  85.                 case "Helicopter":
  86.                     JARVIS.Speak("Okay Sir");
  87.                     break;
  88.                 case "Sports Car":
  89.                     JARVIS.Speak("You May Drive Fast Sir.");
  90.                     break;
  91.                 case "Jarvis":
  92.                     JARVIS.Speak("May I Do Some Moding Sir?");
  93.                     break;
  94.                 case "Which game Is This":
  95.                 case "What game is this":
  96.                 case "Game Name Please":
  97.                     JARVIS.Speak("Sir Its Grand Theft Auto 4");
  98.                     break;
  99.                 case "A Car":
  100.                     JARVIS.Speak("Sports Car Or Normal Car?");
  101.                     break;
  102.                 case "Bike":
  103.                     JARVIS.Speak("As You Wish Sir");
  104.                     break;
  105.                  case "Dont Leave Me Alone":
  106.                 case "Increase wanted level":
  107.                     JARVIS.Speak("Giving You Company Sir");
  108.                     break;
  109.                 case "Leave Me Alone":
  110.                 case "Decrease wanted level":
  111.                     JARVIS.Speak("Bye Cops Dont Need You Anymore");
  112.                     break;
  113.  
  114.                
  115.                    
  116.             }
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement