static async Task Main() { Console.OutputEncoding = Encoding.UTF8; var handler = new SpeechHandler(); foreach (var func in new Func <SpeechHandler, Task <bool> >[] { SelectAudioDeviceAsync, MakeAudioConfigAsync, StartRecognizeSpeechAsync, ListenAsync, Finalize, } ) { var ret = await func.Invoke(handler); if (!ret) { break; } } Console.WriteLine($"END OF PROGRAM"); }
private static async Task <bool> Finalize(SpeechHandler handler) { Console.WriteLine($"Stopping...."); handler.FireStop(); await handler.Recognizer.StopContinuousRecognitionAsync(); return(true); }
private static async Task <bool> ListenAsync(SpeechHandler handler) { await Task.Delay(10); Console.WriteLine("Talk to mic...Push Enter key to exit."); Console.In.ReadLine(); return(true); }
private void Awake() { VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted); //get the voice manager object, and add an event listener to the guide view selected action speechHandler = speechManager.GetComponent <SpeechHandler>(); speechHandler.OnGuideViewSelected += HandleGuideViewSelected; speechHandler.OnGloveTargetConfirmed += HandleGloveTargetConfirmed; }
public void loadData() { List <string> speechLines = new List <string>(); JSONObject obj = new JSONObject(File.ReadAllText(Directory.GetCurrentDirectory() + "/Assets/JSON/testSpeech.JSON")); List <string> responses = new List <string>(); responses = SpeechHandler.AccessData(obj, "TestCharacter").ToList(); speechLines.Add("These are test lines"); speechLines.Add("TEST"); //check if they are the same as the file Assert.AreEqual(speechLines, responses); }
private async Task <bool> StartRecognizeSpeechAsync(SpeechHandler handler) { handler.Recognizer = new SpeechRecognizer(SpeechConfig.FromSubscription(Hot.Setting.SubscriptionKey, Hot.Setting.ServiceRegion), GetTargetRecognizeLanguage(), handler.AudioConfig); handler.Recognizer.Recognizing += OnRecognizing; handler.Recognizer.Recognized += OnRecognized; handler.Recognizer.Canceled += OnCancel; handler.Recognizer.SessionStarted += OnSessionStarted; handler.Recognizer.SessionStopped += OnSessionStopped; handler.Recognizer.SpeechStartDetected += OnSpeechStartDetected; handler.Recognizer.SpeechEndDetected += OnSpeechEndDetected; await handler.Recognizer.StartContinuousRecognitionAsync(); return(true); }
public void QuestionPassenger() { if (PassengerArrested || PassengerPickedUp) { return; } GameFiber.StartNew(delegate { Questioning = true; //WeaponDescriptor currentweapon = Game.LocalPlayer.Character.Inventory.EquippedWeapon; if (Passenger.IsInAnyVehicle(false)) { Passenger.Tasks.LeaveVehicle(LeaveVehicleFlags.None).WaitForCompletion(6000); Vector3 directionFromPassengerToPlayer = (Game.LocalPlayer.Character.Position - Passenger.Position); directionFromPassengerToPlayer.Normalize(); float HeadingToPlayer = MathHelper.ConvertDirectionToHeading(directionFromPassengerToPlayer); Passenger.Tasks.AchieveHeading(HeadingToPlayer); } while (true) { if (Solicitation.ActiveSolicitationTrafficStop == null || Functions.IsPedGettingArrested(Passenger) || Functions.IsPedArrested(Passenger)) { break; } int index = SpeechHandler.DisplayAnswers(QuestionsForPassenger, Shuffle: false); if (index <= 0) { break; } else { SpeechHandler.HandleSpeech("Passenger", PassengerAnswers[index - 1]); PassengerAnswers.RemoveAt(index - 1); QuestionsForPassenger.RemoveAt(index); } } if (!Passenger.IsInAnyVehicle(false)) { Passenger.Tasks.EnterVehicle(veh, 5000, 0).WaitForCompletion(); } Game.DisplayHelp("Press ~b~E ~s~to open the Solicitation Traffic Stop menu."); Questioning = false; }); }
private static async Task <bool> StartRecognizeSpeechAsync(SpeechHandler handler) { var param = new MySecretParameter(); handler.Recognizer = new SpeechRecognizer(SpeechConfig.FromSubscription(param.SubscriptionKey, param.ServiceRegion), "ja-JP", handler.AudioConfig); handler.Recognizer.Recognizing += OnRecognizing; handler.Recognizer.Recognized += OnRecognized; handler.Recognizer.Canceled += OnCancel; handler.Recognizer.SessionStarted += OnSessionStarted; handler.Recognizer.SessionStopped += OnSessionStopped; handler.Recognizer.SpeechStartDetected += OnSpeechStartDetected; handler.Recognizer.SpeechEndDetected += OnSpeechEndDetected; await handler.Recognizer.StartContinuousRecognitionAsync(); return(true); }
void Start() { panel = transform.GetChild(0).gameObject; startSpeech = transform.GetChild(1).gameObject; cancelSpeech = transform.GetChild(2).gameObject; speechHandler = UnityEngine.Object.FindObjectOfType <SpeechHandler>(); #if UNITY_EDITOR GameObject debugObject = GameObject.Find("DebugMesh"); if (debugObject != null) { debugText = debugObject.GetComponent <Text>(); } #endif IsListening = false; Enabled = true; SpeechManager = new SpeechRecognizerManager(gameObject.name); DebugLog("Devices: " + String.Join(", ", Microphone.devices)); if (Application.platform != RuntimePlatform.Android) { Debug.Log("Speech recognition is only available on Android platform."); Enabled = false; return; } if (!SpeechRecognizerManager.IsAvailable()) { Debug.Log("Speech recognition is not available on this device."); Enabled = false; return; } if (!GameState.Instance.SpeechEnabled) { Enabled = false; } // We pass the game object's name that will receive the callback messages. SpeechManager = new SpeechRecognizerManager(gameObject.name); }
private async Task <bool> SelectAudioDeviceAsync(SpeechHandler handler) { // SELECT A AUDIO DEVICE var devices = GetDeviceEndpoints(); foreach (var device in devices) { if (device.ID == GetTargetDeviceID()) { handler.Device = device; LOG.WriteMesLine(GetType().Name, "DeviceInitialized", device.FriendlyName); return(true); } } LOG.WriteMesLine(GetType().Name, "NoDeviceID", Hot.Setting.Device2ID); await Task.Delay(20); return(false); }
private async Task Setup(SpeechHandler handler) { _handlers.Enqueue(handler); var taskList = new Func <SpeechHandler, Task <bool> >[] { SelectAudioDeviceAsync, MakeAudioConfigAsync, StartRecognizeSpeechAsync, }; foreach (var func in taskList) { var ret = await func.Invoke(handler); if (!ret) { break; } } }
private static async Task <bool> SelectAudioDeviceAsync(SpeechHandler handler) { // SELECT A AUDIO DEVICE var devices = new MMDeviceEnumerator().EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active); handler.Device = null; while (handler.Device == null) { Console.WriteLine("Select an audio device."); for (var i = 0; i < devices.Count; i++) { var device = devices[i]; Console.WriteLine($" [{i + 1}] : {device.FriendlyName}"); } Console.WriteLine(" [Q] Quit."); Console.Write("> "); try { var line = Console.In.ReadLine()?.ToUpper().Trim(); if (line == "Q") { return(false); } var no = int.Parse(line); if (no > 0 && no <= devices.Count) { handler.Device = devices[no - 1]; } } catch { } await Task.Delay(300); Console.WriteLine(); } return(true); }
void Start() { //Initialises Variables //Response Arrays speechData = new JSONObject(speechFile.text); Debug.Log("Accessing JSON: "); foreach (var character in speechData.keys) { if (character == "Pirate") { pirateResponses = SpeechHandler.AccessData(speechData, character).ToList().ToList(); } else if (character == "Mime") { mimeResponses = SpeechHandler.AccessData(speechData, character).ToList().ToList(); } else if (character == "Millionaire") { millionaireResponses = SpeechHandler.AccessData(speechData, character).ToList(); } else if (character == "Cowgirl") { cowgirlResponses = SpeechHandler.AccessData(speechData, character).ToList(); } else if (character == "Roman") { romanResponses = SpeechHandler.AccessData(speechData, character).ToList(); } else if (character == "Wizard") { wizardResponses = SpeechHandler.AccessData(speechData, character).ToList(); } else if (character == "Chubbie") { chubbieResponses = SpeechHandler.AccessData(speechData, character).ToList(); } else if (character == "HeMan") { hemanResponses = SpeechHandler.AccessData(speechData, character).ToList(); } else if (character == "Reginald") { reginaldResponses = SpeechHandler.AccessData(speechData, character).ToList(); } else if (character == "Scientist") { scientistResponses = SpeechHandler.AccessData(speechData, character).ToList(); } //Saving and loading } //Weaknesses List <string> pirateWeaknesses = new List <string> { "Forceful", "Wisecracking", "Kind" }; List <string> mimeWeaknesses = new List <string> { "Intimidating", "Coaxing", "Inspiring" }; List <string> millionaireWeaknesses = new List <string> { "Forceful", "Rushed", "Kind" }; List <string> cowgirlWeaknesses = new List <string> { "Condescending", "Wisecracking", "Inspiring" }; List <string> romanWeaknesses = new List <string> { "Condescending", "Coaxing", "Inquisitive" }; List <string> wizardWeaknesses = new List <string> { "Intimidating", "Rushed", "Inquisitive" }; List <string> chubbieWeaknesses = new List <string> { "Condescending", "Wizecracking", "Kind" }; //ADDITION BY WEDUNNIT List <string> scientistWeaknesses = new List <string> { "Forceful", "Coaxing", "Inspiring" }; //ADDITION BY WEDUNNIT List <string> reginaldWeaknesses = new List <string> { "Forceful", "Coaxing", "Inspiring" }; //ADDITION BY WEDUNNIT List <string> hemanWeaknesses = new List <string> { "Condescending", "Rushed", "Kind" }; //ADDITION BY WEDUNNIT //Defining NPC's NonPlayerCharacter reginald = new NonPlayerCharacter("Reginald Montgomery IV", reginaldSprite, "Reginald M IV", reginaldPref, reginaldWeaknesses, reginaldResponses); //ADDITION BY WEDUNNIT NonPlayerCharacter pirate = new NonPlayerCharacter("Captain Bluebottle", pirateSprite, "Salty Seadog", piratePref, pirateWeaknesses, pirateResponses); NonPlayerCharacter mimes = new NonPlayerCharacter("The Mime Twins", mimesSprite, "mimes", mimesPref, mimeWeaknesses, mimeResponses); NonPlayerCharacter millionaire = new NonPlayerCharacter("Sir Worchester", millionaireSprite, "Money Bags", millionarePref, millionaireWeaknesses, millionaireResponses); NonPlayerCharacter cowgirl = new NonPlayerCharacter("Jesse Ranger", cowgirlSprite, "Outlaw", cowgirlPref, cowgirlWeaknesses, cowgirlResponses); NonPlayerCharacter roman = new NonPlayerCharacter("Celcius Maximus", romanSprite, "Legionnaire", romanPref, romanWeaknesses, romanResponses); NonPlayerCharacter wizard = new NonPlayerCharacter("Randolf the Deep Purple", wizardSprite, "Dodgy Dealer", wizardPref, wizardWeaknesses, wizardResponses); NonPlayerCharacter chubbie = new NonPlayerCharacter("Tinky Wobbly", chubbieSprite, "Telechubbie", chubbiePref, chubbieWeaknesses, chubbieResponses); //ADDITION BY WEDUNNIT NonPlayerCharacter heman = new NonPlayerCharacter("HisMan", hemanSprite, "Superhero", hemanPref, hemanWeaknesses, hemanResponses); //ADDITION BY WEDUNNIT NonPlayerCharacter scientist = new NonPlayerCharacter("Dr Emmanuel Brown", scientistSprite, "Mad scientist", scientistPref, scientistWeaknesses, scientistResponses); //ADDITION BY WEDUNNIT //Defining Scenes Scene controlRoom = new Scene("Control Room"); Scene kitchen = new Scene("Kitchen"); Scene lectureTheatre = new Scene("Lecture Theatre"); Scene lakehouse = new Scene("Lakehouse"); Scene islandOfInteraction = new Scene("Island of Interaction"); Scene roof = new Scene("Roof"); Scene atrium = new Scene("Atrium"); Scene undergroundLab = new Scene("Underground Lab"); Scene factory = new Scene("Factory"); //Defining Items MurderWeapon cutlass = new MurderWeapon(cutlassPrefab, "Cutlass", "A worn and well used cutlass", cutlassSprite, "SD"); MurderWeapon poison = new MurderWeapon(poisonPrefab, "Empty Poison Bottle", "This had poison in once ", poisonSprite, "SD"); MurderWeapon garrote = new MurderWeapon(garrotePrefab, "Garrote", "Used for strangling someone... to death!", garroteSprite, "SD"); MurderWeapon knife = new MurderWeapon(knifePrefab, "Knife", "A sharp tool meant for cutting meat", knifeSprite, "SD"); MurderWeapon laserGun = new MurderWeapon(laserGunPrefab, "Laser Gun", "It's still warm, implying it has been recently fired", laserGunSprite, "SD"); MurderWeapon leadPipe = new MurderWeapon(leadPipePrefab, "Lead Pipe", "It's a bit battered with a few dents on the side", leadPipeSprite, "SD"); MurderWeapon westernPistol = new MurderWeapon(westernPistolPrefab, "Western Pistol", "The gunpowder residue implies it has been recently fired", westernPistolSprite, "SD"); MurderWeapon wizardStaff = new MurderWeapon(wizardStaffPrefab, "Wizard Staff", "The gems still seem to be glow as if it has been used recently", wizardStaffSprite, "SD"); Item beret = new Item(beretPrefab, "Beret", "A hat most stereotypically worn by the French", beretSprite); Item footprints = new Item(footprintsPrefab, "Bloody Footprints", "Bloody footprints most likely left by the murderer", footprintsSprite); Item gloves = new Item(glovesPrefab, "Bloody Gloves", "Bloody gloves most likely used by the murderer", glovesSprite); Item wine = new Item(winePrefab, "Fine Wine", "An expensive vintage that's close to 100 years old", wineSprite); Item shatteredGlass = new Item(shatteredGlassPrefab, "Shattered Glass", "Broken glass shards spread quite close together", shatteredGlassSprite); Item shrapnel = new Item(shrapnelPrefab, "Shrapnel", "Shrapnel from an explosion or gun being fired", shrapnelSprite); Item smellyDeath = new Item(smellyDeathPrefab, "Smelly Ashes", "All that remains of the victim", smellyDeathSprite); Item spellbook = new Item(spellbookPrefab, "Spellbook", "A spellbook used by those who practise in the magic arts", spellbookSprite); Item tripwire = new Item(tripwirePrefab, "Tripwire", "A used tripwire most likely used to immobilize the victim", tripwireSprite); Item chefHat = new Item(chefHatPrefab, "Chef's Hat", "A clean and fresh smelling hat, worn by chefs.", chefHatSprite); //ADDITION BY WEDUNNIT Item whistle = new Item(whistlePrefab, "Whistle", "A bright, shiny whistle that's as clean as... well.", whistleSprite); //ADDITION BY WEDUNNIT Item toast = new Item(toastPrefab, "Toast", "A slice of well buttered toast. It's slightly warm.", toastSprite); //ADDITION BY WEDUNNIT Item stapler = new Item(staplerPrefab, "Stapler", "A bright red stapler, with no staples in it.", staplerSprite); //ADDITION BY WEDUNNIT Item seaweed = new Item(seaweedPrefab, "Seaweed", "Oceanman, take me by the hand lead me to the land, that you understand.", seaweedSprite); //ADDITION BY WEDUNNIT Item sandwitch = new Item(sandwichPrefab, "Sandwich", "A ham sandwich with cheese and lettuce on white bread.", sandwitchSprite); //ADDITION BY WEDUNNIT Item purse = new Item(pursePrefab, "Fancy Purse", "A finely made, hand crafted, now-empty purse.", purseSprite); //ADDITION BY WEDUNNIT Item plunger = new Item(plungerPrefab, "Plunger", "A toilet plunger. It hasn't been used recently.", plungerSprite); //ADDITION BY WEDUNNIT Item monocle = new Item(monoclePrefab, "Monocle", "A finely made monocle, complete with gold chain.", monocleSprite); //ADDITION BY WEDUNNIT Item feather = new Item(featherPrefab, "Feather", "A goose feather, apparently freshly plucked.", featherSprite); //ADDITION BY WEDUNNIT Item glasses = new Item(glassesPrefab, "Safety Glasses", "Safety glasses good for keeping splinters and acid out of the eyes.", glassesSprite); //ADDITION BY WEDUNNIT Item dumbbell = new Item(dumbbellPrefab, "Dumbbbell", "Dumbbells; the source of pure strength.", dumbbellSprite); //ADDITION BY WEDUNNIT murderWeapons = new MurderWeapon[8] { cutlass, poison, garrote, knife, laserGun, leadPipe, westernPistol, wizardStaff }; itemClues = new Item [21] { beret, footprints, gloves, wine, shatteredGlass, shrapnel, smellyDeath, spellbook, tripwire, whistle, chefHat, toast, stapler, seaweed, sandwitch, purse, plunger, monocle, feather, dumbbell, glasses }; characters = new NonPlayerCharacter[10] { pirate, mimes, millionaire, cowgirl, roman, wizard, heman, chubbie, scientist, reginald }; scenes = new Scene[9] { atrium, lectureTheatre, lakehouse, controlRoom, kitchen, islandOfInteraction, roof, undergroundLab, factory }; }
private void CalloutHandler() { CalloutRunning = true; GameFiber.StartNew(delegate { try { //Responding... Suspect.Tasks.CruiseWithVehicle(SuspectCar, 17f, VehicleDrivingFlags.Normal); Game.DisplayNotification("3dtextures", "mpgroundlogo_cops", "Assorted Callouts", PetrolGas + " Theft", "~b~Control: ~s~We have reports of a ~r~" + PetrolGas.ToLower() + " theft. ~s~Please respond ~b~CODE 2~s~."); Functions.PlayScannerAudio("REPORT_RESPONSE_COPY UNITS_RESPOND_CODE_02_02"); while (CalloutRunning) { GameFiber.Yield(); Rage.Native.NativeFunction.Natives.SET_DRIVE_TASK_DRIVING_STYLE(Suspect, 786603); if (Vector3.Distance(Game.LocalPlayer.Character.Position, Shopkeeper.Position) < 15f) { ShopkeeperBlip.IsRouteEnabled = false; Vector3 directionFromShopkeeperToCar = (Game.LocalPlayer.Character.Position - Shopkeeper.Position); directionFromShopkeeperToCar.Normalize(); Shopkeeper.Tasks.AchieveHeading(MathHelper.ConvertDirectionToHeading(directionFromShopkeeperToCar)).WaitForCompletion(1100); Shopkeeper.Tasks.PlayAnimation("friends@frj@ig_1", "wave_a", 1.1f, AnimationFlags.Loop); if (!Game.LocalPlayer.Character.IsInAnyVehicle(false)) { if (ComputerPlusRunning) { API.ComputerPlusFuncs.SetCalloutStatusToAtScene(CalloutID); } break; } } } //On scene while (CalloutRunning) { GameFiber.Yield(); if (Vector3.Distance(Game.LocalPlayer.Character.Position, Shopkeeper.Position) < 6f) { Game.DisplayHelp("Press ~b~" + AssortedCalloutsHandler.kc.ConvertToString(AssortedCalloutsHandler.TalkKey) + " ~s~to talk."); if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(AssortedCalloutsHandler.TalkKey)) { Shopkeeper.Tasks.ClearImmediately(); break; } } else { Game.HideHelp(); } } ShopkeeperBlip.Delete(); //CCTV and Dialogue DetermineShopkeeperLines(); SpeechHandler.HandleSpeech("Shopkeeper", ShopkeeperLines, Shopkeeper); if (ShowCCTV) { GameFiber.Sleep(2000); WatchCameraFootage(); } ShopkeeperLines.Clear(); if (ShopkeeperKnowsVehicleDetails) { ShopkeeperLines.Add("The vehicle was a ~b~" + CarColor + " ~b~" + CarModelName + " ~s~."); ShopkeeperLines.Add("The licence plate was ~b~" + SuspectCar.LicensePlate + "."); ShopkeeperLines.Add("They took off in that direction!"); SpeechHandler.HandleSpeech("Shopkeeper", ShopkeeperLines, Shopkeeper); } else { OfficerLines = new List <string>() { "I can make out the vehicle's details from the CCTV footage!", "The vehicle was a ~b~" + CarColor + " ~b~" + CarModelName + ".", "The licence plate was ~b~" + SuspectCar.LicensePlate + ".", "In which direction did they go?" }; SpeechHandler.HandleSpeech("You", OfficerLines, Game.LocalPlayer.Character); ShopkeeperLines.Clear(); ShopkeeperLines.Add("They made off in that direction, officer!"); SpeechHandler.HandleSpeech("Shopkeeper", ShopkeeperLines, Shopkeeper); } GameFiber.Yield(); SuspectCar.Position = Game.LocalPlayer.Character.Position.Around(250f).GetClosestMajorVehicleNode(); while (Vector3.Distance(SuspectCar.Position, Game.LocalPlayer.Character.Position) < 170f) { GameFiber.Yield(); SuspectCar.Position = Game.LocalPlayer.Character.Position.Around(250f).GetClosestMajorVehicleNode(); } Vector3 directionFromShopkeeperToCar1 = (SuspectCar.Position - Shopkeeper.Position); directionFromShopkeeperToCar1.Normalize(); Shopkeeper.Tasks.AchieveHeading(MathHelper.ConvertDirectionToHeading(directionFromShopkeeperToCar1)).WaitForCompletion(1200); Shopkeeper.Tasks.PlayAnimation("gestures@f@standing@casual", "gesture_point", 0.8f, AnimationFlags.Loop); GameFiber.Sleep(3000); Game.DisplayNotification("Control, ~r~suspect's vehicle~s~ is a ~b~" + CarColor + " ~b~" + CarModelName + "."); GameFiber.Sleep(2000); Game.DisplayNotification("The plate is ~b~" + SuspectCar.LicensePlate + ". ~s~~n~Please pass on the details, I'm ~b~checking the area~s~, over."); if (ComputerPlusRunning) { API.ComputerPlusFuncs.AddUpdateToCallout(CalloutID, "Suspect's vehicle is a " + CarColor + " " + CarModelName + "."); API.ComputerPlusFuncs.AddUpdateToCallout(CalloutID, "The plate is " + SuspectCar.LicensePlate + ". Checking the area."); } //Searching... HandleSearchForVehicleWithANPR(); if (ComputerPlusRunning) { API.ComputerPlusFuncs.AddUpdateToCallout(CalloutID, "Vehicle located. Engaging traffic stop."); } //float Radius = 140f; //bool RouteEnabled = false; //SearchArea = new Blip(SuspectCar.Position.Around(35f), Radius); //SearchArea.Color = System.Drawing.Color.Yellow; //SearchArea.Alpha = 0.5f; //Shopkeeper.Tasks.ClearImmediately(); //Suspect.Tasks.CruiseWithVehicle(SuspectCar, 18f, VehicleDrivingFlags.Normal); //int WaitCount = 0; //int WaitCountTarget = 3100; //while (CalloutRunning) //{ // GameFiber.Yield(); // WaitCount++; // Rage.Native.NativeFunction.Natives.SET_DRIVE_TASK_DRIVING_STYLE( Suspect, 786603); // if (Vector3.Distance(Game.LocalPlayer.Character.GetOffsetPosition(Vector3.RelativeFront * 9f), SuspectCar.Position) < 9f) // { // GameFiber.Sleep(2000); // if (Vector3.Distance(Game.LocalPlayer.Character.GetOffsetPosition(Vector3.RelativeFront * 9f), SuspectCar.Position) < 9f) // { // Game.DisplayNotification("Control, I have located the ~b~" + CarModelName + "~s~ from the ~r~" + PetrolGas.ToLower() + " theft."); // Game.DisplayNotification("I'm preparing to ~b~stop them,~s~ over."); // SuspectBlip = Suspect.AttachBlip(); // if (SearchArea.Exists()) { SearchArea.Delete(); } // Functions.PlayScannerAudio("DISPATCH_SUSPECT_LOCATED_ENGAGE REPORT_RESPONSE"); // break; // } // } // else if (((Vector3.Distance(SuspectCar.Position, SearchArea.Position) > Radius + 230f) && (WaitCount > 1000)) || (WaitCount > WaitCountTarget)) // { // Game.DisplayNotification("~b~Control: ~s~We have an ~o~ANPR Hit ~s~on ~b~" + SuspectCar.LicensePlate + ". ~g~Search area updated, ~s~over."); // Functions.PlayScannerAudioUsingPosition("WE_HAVE_01 CRIME_TRAFFIC_ALERT IN_OR_ON_POSITION", SuspectCar.Position); // SearchArea.Delete(); // Radius = 50f; // SearchArea = new Blip(SuspectCar.Position.Around(8f), Radius); // SearchArea.Color = System.Drawing.Color.Yellow; // SearchArea.Alpha = 0.5f; // RouteEnabled = false; // if (WaitCount > WaitCountTarget) { Game.LogTrivial("Updated for waitcount"); } // WaitCount = 0; // Suspect.Tasks.PerformDrivingManeuver(VehicleManeuver.Wait).WaitForCompletion(1000); // Suspect.Tasks.CruiseWithVehicle(SuspectCar, 17f, VehicleDrivingFlags.DriveAroundVehicles | VehicleDrivingFlags.DriveAroundObjects | VehicleDrivingFlags.DriveAroundPeds); // WaitCountTarget -= EntryPoint.rnd.Next(200,500); // if (WaitCountTarget < 1900) { WaitCountTarget = 1900; } // } // if (Vector3.Distance(Game.LocalPlayer.Character.Position, SearchArea.Position) > Radius + 90f) // { // if (!RouteEnabled) // { // SearchArea.IsRouteEnabled = true; // RouteEnabled = true; // } // } // else // { // if (RouteEnabled) // { // SearchArea.IsRouteEnabled = false; // RouteEnabled = false; // } // } //} //Found while (CalloutRunning) { GameFiber.Yield(); if (!CalloutRunning) { break; } if (!Game.LocalPlayer.Character.IsInAnyVehicle(false)) { break; } if (Functions.IsPlayerPerformingPullover()) { if (Functions.GetPulloverSuspect(Functions.GetCurrentPullover()) == Suspect) { break; } } } if (Functions.IsPlayerPerformingPullover()) { GameFiber.Wait(3000); } //How they react: if (SuspectBlip.Exists()) { SuspectBlip.Delete(); } if ((AssortedCalloutsHandler.rnd.Next(11) <= 5) || (!Game.LocalPlayer.Character.IsInAnyVehicle(false)) || Functions.GetActivePursuit() != null) { if (CalloutRunning) { if (Functions.GetActivePursuit() != null) { Functions.ForceEndPursuit(Functions.GetActivePursuit()); } Pursuit = Functions.CreatePursuit(); Functions.AddPedToPursuit(Pursuit, Suspect); Functions.SetPursuitIsActiveForPlayer(Pursuit, true); if (Functions.IsPlayerPerformingPullover()) { Functions.ForceEndCurrentPullover(); } Functions.PlayScannerAudioUsingPosition("WE_HAVE CRIME_RESIST_ARREST IN_OR_ON_POSITION", Game.LocalPlayer.Character.Position); if (AssortedCalloutsHandler.English == AssortedCalloutsHandler.EnglishTypes.BritishEnglish) { Game.DisplayNotification("Control, the vehicle is ~r~making off.~b~ Giving chase."); } else { Game.DisplayNotification("Control, the vehicle is ~r~fleeing,~b~ In pursuit."); } if (ComputerPlusRunning) { API.ComputerPlusFuncs.AddUpdateToCallout(CalloutID, "Vehicle is fleeing. Engaging pursuit."); } while (Functions.IsPursuitStillRunning(Pursuit)) { GameFiber.Yield(); if (!CalloutRunning) { break; } } } } else { while (CalloutRunning) { GameFiber.Yield(); if (!Game.LocalPlayer.Character.IsInAnyVehicle(false)) { GameFiber.Wait(1000); if (AssortedCalloutsHandler.rnd.Next(5) == 0) { Pursuit = Functions.CreatePursuit(); Functions.AddPedToPursuit(Pursuit, Suspect); Functions.SetPursuitIsActiveForPlayer(Pursuit, true); if (Functions.IsPlayerPerformingPullover()) { Functions.ForceEndCurrentPullover(); } Functions.PlayScannerAudioUsingPosition("WE_HAVE CRIME_RESIST_ARREST IN_OR_ON_POSITION", Game.LocalPlayer.Character.Position); if (AssortedCalloutsHandler.English == AssortedCalloutsHandler.EnglishTypes.BritishEnglish) { Game.DisplayNotification("Control, the vehicle is ~r~making off.~b~ Giving chase."); } else { Game.DisplayNotification("Control, the vehicle is ~r~fleeing,~b~ In pursuit."); } if (ComputerPlusRunning) { API.ComputerPlusFuncs.AddUpdateToCallout(CalloutID, "Vehicle is fleeing. Engaging pursuit."); } } break; } } while (CalloutRunning) { GameFiber.Yield(); if (Suspect.Exists()) { if (Functions.IsPedArrested(Suspect)) { break; } if (Suspect.IsDead) { break; } } else { break; } } } //Done if (Suspect.Exists()) { if (Functions.IsPedArrested(Suspect)) { msg = "Control, suspect is ~g~under arrest. ~s~The ~r~" + PetrolGas.ToLower() + " theft~s~ call is ~g~CODE 4~s~, over."; } else if (Suspect.IsDead) { msg = "Control, suspect is ~r~dead. ~s~The ~r~" + PetrolGas.ToLower() + " theft~s~ call is ~g~CODE 4~s~, over."; } } else { msg = "Control, the suspects ~r~have escaped. ~s~The ~r~" + PetrolGas.ToLower() + " theft~s~ call is ~g~CODE 4~s~, over."; } if (CalloutRunning) { GameFiber.Sleep(4000); Game.DisplayNotification("3dtextures", "mpgroundlogo_cops", "Assorted Callouts", PetrolGas + " Theft", msg); Functions.PlayScannerAudio("ATTENTION_THIS_IS_DISPATCH_HIGH WE_ARE_CODE FOUR NO_FURTHER_UNITS_REQUIRED"); CalloutFinished = true; End(); } } catch (Exception e) { Game.LogTrivial(e.ToString()); End(); } }); }
private void SituationTwo() { StolenGoodsValue = AssortedCalloutsHandler.rnd.Next(5, 500); SpawnStorePeds(); while (CalloutRunning) { GameFiber.Yield(); if (Vector3.Distance(Game.LocalPlayer.Character.Position, SearchArea) < 150f) { SearchArea.IsRouteEnabled = false; break; } } if (ComputerPlusRunning) { API.ComputerPlusFuncs.SetCalloutStatusToAtScene(CalloutID); } if (CalloutRunning) { SearchArea.Delete(); Suspects[0].Position = World.GetNextPositionOnStreet(Suspects[0].Position); Pursuit = Functions.CreatePursuit(); Functions.AddPedToPursuit(Pursuit, Suspects[0]); Functions.SetPedAsCop(Security[0]); Security[0].MakeMissionPed(); Functions.AddCopToPursuit(Pursuit, Security[0]); Functions.SetPursuitIsActiveForPlayer(Pursuit, true); Game.DisplayNotification("3dtextures", "mpgroundlogo_cops", "~b~" + ShopliftingStore.Name + " ~r~shoplifting", "Dispatch to ~b~" + AssortedCalloutsHandler.DivisionUnitBeat, "Suspect has reportedly escaped from the store and is now being chased by security. Apprehend the suspect."); Functions.PlayScannerAudioUsingPosition("WE_HAVE_01 CRIME_RESIST_ARREST IN_OR_ON_POSITION", SpawnPoint); } while (CalloutRunning) { GameFiber.Yield(); if (!Functions.IsPursuitStillRunning(Pursuit)) { GameFiber.Wait(3000); SearchArea = ShopKeepers[0].AttachBlip(); SearchArea.Color = System.Drawing.Color.Yellow; SearchArea.IsRouteEnabled = true; break; } } while (CalloutRunning) { GameFiber.Yield(); if (Vector3.Distance(Game.LocalPlayer.Character.Position, ShopKeepers[0].Position) < 4f) { if (SearchArea.Exists()) { SearchArea.IsRouteEnabled = false; SearchArea.Delete(); } Game.DisplayHelp("Press ~b~" + AssortedCalloutsHandler.kc.ConvertToString(AssortedCalloutsHandler.TalkKey) + " ~s~to talk."); if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(AssortedCalloutsHandler.TalkKey)) { ShopKeepers[0].Tasks.ClearImmediately(); SpeechHandler.HandleSpeech("Shopkeeper", DetermineShopkeeperLines(), ShopKeepers[0]); GameFiber.Wait(4000); break; } } else { Game.DisplayHelp("Talk to the ~b~shopkeeper ~s~for a victim statement."); } } while (CalloutRunning) { GameFiber.Yield(); Game.DisplayHelp("Press ~b~" + AssortedCalloutsHandler.kc.ConvertToString(AssortedCalloutsHandler.EndCallKey) + " ~s~when you're done investigating."); if (Game.IsKeyDown(AssortedCalloutsHandler.EndCallKey)) { Game.HideHelp(); break; } } DisplayCodeFourMessage(); }
public void TestSetup() { testSpeechHandler = new SpeechHandler(); testStory = new Story(); testStory.setStory(); }
private static async Task <bool> MakeAudioConfigAsync(SpeechHandler handler) { // var audioConfig = AudioConfig.FromWavFileInput(@"D:\Users\ManabuTonosaki\OneDrive - tomarika\tono.wav"); // var audioConfig = AudioConfig.FromDefaultMicrophoneInput(); Debug.Assert(handler.Device != null); var wavein = new WasapiLoopbackCapture(handler.Device); var waveoutFormat = new WaveFormat(16000, 16, 1); var lastSpeakDT = DateTime.Now; var willStop = DateTime.MaxValue; wavein.DataAvailable += (s, e) => { if (e.BytesRecorded > 0) { using var ms = new MemoryStream(e.Buffer, 0, e.BytesRecorded); using var rs = new RawSourceWaveStream(ms, wavein.WaveFormat); using var freq = new MediaFoundationResampler(rs, waveoutFormat.SampleRate); var w16 = freq.ToSampleProvider().ToMono().ToWaveProvider16(); var len = w16.Read(handler.buf, 0, handler.buf.Length); handler.AudioInputStream.Write(handler.buf, len); lastSpeakDT = DateTime.Now; willStop = DateTime.MaxValue; } else { if (DateTime.Now < willStop) { if (willStop == DateTime.MaxValue) { willStop = DateTime.Now + TimeSpan.FromSeconds(10); } var silence = new SilenceProvider(waveoutFormat); var len = silence.Read(handler.buf, 0, waveoutFormat.BitsPerSample * waveoutFormat.SampleRate / 8 / 100); // 10ms var cnt = (int)((DateTime.Now - lastSpeakDT).TotalMilliseconds / 10); for (var i = 0; i < cnt; i++) { handler.AudioInputStream.Write(handler.buf, len); } lastSpeakDT = DateTime.Now; } } }; var audioformat = AudioStreamFormat.GetWaveFormatPCM(samplesPerSecond: 16000, bitsPerSample: 16, channels: 1); handler.AudioInputStream = AudioInputStream.CreatePushStream(audioformat); handler.AudioConfig = AudioConfig.FromStreamInput(handler.AudioInputStream); await Task.Delay(100); handler.StopRequested += (s, e) => { wavein.StopRecording(); }; wavein.StartRecording(); return(true); }
private void SituationOne() { //One robber, one shopkeeper. Wait, fight, flee (pursuit). StolenGoodsValue = AssortedCalloutsHandler.rnd.Next(5, 300); SpawnStorePeds(); while (CalloutRunning) { GameFiber.Yield(); if (Vector3.Distance(Game.LocalPlayer.Character.Position, SearchArea) < 40f) { SearchArea.IsRouteEnabled = false; break; } } if (ComputerPlusRunning) { API.ComputerPlusFuncs.SetCalloutStatusToAtScene(CalloutID); } while (CalloutRunning) { GameFiber.Yield(); if (NativeFunction.Natives.GET_INTERIOR_FROM_ENTITY <int>(Game.LocalPlayer.Character) != 0) { SpeechHandler.HandleSpeech("Shopkeeper", "Hey officer, the scumbag is in the back!"); break; } } while (CalloutRunning) { GameFiber.Yield(); if (Vector3.Distance(Game.LocalPlayer.Character.Position, Security[0].Position) < 4f) { Game.DisplayHelp("Press ~b~" + AssortedCalloutsHandler.kc.ConvertToString(AssortedCalloutsHandler.TalkKey) + " ~s~to talk."); if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(AssortedCalloutsHandler.TalkKey)) { Security[0].Tasks.ClearImmediately(); break; } } else { Game.HideHelp(); } } if (CalloutRunning) { SearchArea.Delete(); DetermineSecurityLines(); SpeechHandler.HandleSpeech("Security", DetermineSecurityLines(), Security[0]); SpeechHandler.HandleSpeech("Suspect", DetermineSuspectLines(), Suspects[0]); } while (CalloutRunning) { GameFiber.Yield(); Game.DisplayHelp("Deal with the situation as you see fit. Press ~b~" + AssortedCalloutsHandler.kc.ConvertToString(AssortedCalloutsHandler.EndCallKey) + " ~s~when done."); if (Game.IsKeyDown(AssortedCalloutsHandler.EndCallKey)) { Game.HideHelp(); break; } } DisplayCodeFourMessage(); }
private async Task <bool> MakeAudioConfigAsync(SpeechHandler handler) { Debug.Assert(handler.Device != null); // NAudio Setting var wavein = CreateCaptureInstance(handler.Device); var waveoutFormat = new WaveFormat(16000, 16, 1); wavein.StartRecording(); // Azure Cognitive Service Setting var audioformat = AudioStreamFormat.GetWaveFormatPCM((uint)waveoutFormat.SampleRate, (byte)waveoutFormat.BitsPerSample, (byte)waveoutFormat.Channels); handler.AudioInputStream = AudioInputStream.CreatePushStream(audioformat); handler.AudioConfig = AudioConfig.FromStreamInput(handler.AudioInputStream); // Silence Generate DateTime preEvent = DateTime.Now; var silenceData = new byte[waveoutFormat.BlockAlign]; // Appliation Preparation Hot.SetWavFormat(DisplayName, waveoutFormat); // for file saving // NAudio Voice event wavein.DataAvailable += (s, e) => { if (e.BytesRecorded > 0) { var now = DateTime.Now; using (var ms = new MemoryStream()) { var memoryWriter = new WaveFileWriter(ms, waveoutFormat); ms.SetLength(0); // Delete file header. var samples = Resample(wavein.WaveFormat, e.Buffer, e.BytesRecorded, waveoutFormat); foreach (var sample in samples) { memoryWriter.WriteSample(sample); } Hot.AddWavToAllQueue(DisplayName, ms.GetBuffer(), (int)ms.Length, now); // for file saving handler.AudioInputStream.Write(ms.GetBuffer(), (int)ms.Length); // for Azure Cognitive Speech to Text } try { Token.Add(TokenWavDataQueued, this); // TODO: Need Confirm it must be fixed with Tono.Gui.WinForm 1.1.2 - System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.' // It must be not fixed yet. so I added try-catch. } catch { // No Action because the above token is a QoS 0 message. But it's necessary to disappear exception messages that's why catch them here. } preEvent = DateTime.Now; } else { if (_talkID != null) { var spms = (double)waveoutFormat.SampleRate / 1000; // samples per ms var n = (int)(spms * (DateTime.Now - preEvent).TotalMilliseconds); for (var i = n; i >= 0; i--) { handler.AudioInputStream.Write(silenceData, silenceData.Length); // send silence to azure to get realtime event (othewise, azure will wait untile next event timing even if there is no event long time) } } preEvent = DateTime.Now; } }; handler.StopRequested += (s, e) => { wavein.StopRecording(); // Stop NAudio recording }; return(await Task.FromResult(true)); }
private void MainLogic() { CalloutRunning = true; GameFiber.StartNew(delegate { try { DispatchResponse(); WaitForGetClose(); WaitForParkAndGetNearby(); while (CalloutRunning) { GameFiber.Yield(); PoliceCar.ShouldVehiclesYieldToThisVehicle = false; if (Vector3.Distance(Game.LocalPlayer.Character.Position, PoliceOfficer.Position) < 4f) { Game.DisplayHelp("Press ~b~" + AssortedCalloutsHandler.kc.ConvertToString(AssortedCalloutsHandler.TalkKey) + " ~s~to talk."); if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(AssortedCalloutsHandler.TalkKey)) { SpeechHandler.HandleSpeech("Officer", ArrestWarrantSpeeches[AssortedCalloutsHandler.rnd.Next(ArrestWarrantSpeeches.Count)]); PoliceOfficer.Tasks.EnterVehicle(PoliceCar, 5000, -1); break; } } } if (CalloutRunning) { if (Suspect.IsInAnyVehicle(false)) { Suspect.Tasks.LeaveVehicle(LeaveVehicleFlags.None).WaitForCompletion(3000); } } while (CalloutRunning) { GameFiber.Yield(); Suspect.Tasks.FollowNavigationMeshToPosition(Game.LocalPlayer.Character.GetOffsetPosition(Vector3.RelativeBack * 1.5f), Game.LocalPlayer.Character.Heading, 1.4f).WaitForCompletion(500); if (Game.LocalPlayer.Character.LastVehicle.Exists()) { if (Game.LocalPlayer.Character.LastVehicle.DistanceTo(Suspect) < 3f) { Suspect.Tasks.Clear(); Suspect.Tasks.EnterVehicle(Game.LocalPlayer.Character.LastVehicle, 6000, Game.LocalPlayer.Character.LastVehicle.PassengerCapacity - 1).WaitForCompletion(6100); } } if (Suspect.IsInAnyVehicle(false)) { break; } } if (SuspectBlip.Exists()) { SuspectBlip.Delete(); } if (PoliceOfficerBlip.Exists()) { PoliceOfficerBlip.Delete(); } while (CalloutRunning) { GameFiber.Yield(); if (Suspect.Exists()) { if (Functions.IsPedInPrison(Suspect)) { break; } } else { break; } } DisplayCodeFourMessage(); } catch (System.Threading.ThreadAbortException e) { End(); } catch (Exception e) { if (CalloutRunning) { Game.LogTrivial(e.ToString()); Game.LogTrivial("Assorted Callouts handled the exception successfully."); Game.DisplayNotification("~O~Traffic Stop Backup~s~callout crashed, sorry. Please send me your log file."); Game.DisplayNotification("Full LSPDFR crash prevented ~g~successfully."); End(); } } }); }