protected async void RespondToPromptCue(object o, EventArgs <ChoreographyCue> eargs) { CurrentCue = eargs.Value; Classifier = CueClassifiers[CurrentCue.ClassifierKey]; //await GimmeCue(eargs.Value.GestureClass); SelectedGestureClass = Classifier.MatchingDatasetClasses[CurrentCue.GestureClassIndex]; if (CurrentCue.CueTime < DateTime.Now) { Log.Debug(_tag, $"Timing issue - CurrentCue.CueTime is {CurrentCue.CueTime}, now is {DateTime.Now}."); CurrentCue.CueTime = DateTime.Now + TimeSpan.FromMilliseconds(250); } var delay = CurrentCue.CueTime - DateTime.Now; await Task.Delay(delay); Speech.Say(SelectedGestureClass.className, SoundOptions.AtSpeed(2.0)); Stopwatch.Restart(); if (_singleMode) { MeleeChoreographer.Deactivate(); } }
public void SubmitResults(ChoreographyCue MyResultCue, ChoreographyCue OppResultCue) { // This variant completely ignores the CONTENTS of what you just sent back; all it cares about is the fact that you sent 'em now. readyToProceed.Set(); }
protected void ResolveEndOfGesture(Sequence <DKS> resultSequence) { MostRecentSample = resultSequence; if (!_userTrainingMode) { MostRecentSample.TrueClassIndex = SelectedGestureClass.index; } //Dataset?.AddSequence(MostRecentSample); string StageLabel = (!_userTrainingMode) ? $"Cued gesture {SelectedGestureClass.className}#{SelectedGestureClass.numExamples + SelectedGestureClass.numNewExamples}" : $"User gesture (#{Dataset.SequenceCount + 1})"; if (!_advancedCueMode) { ResetStage(StageLabel); } _collectingData = false; if (Classifier == null) { return; } MostRecentSample = Analyze(MostRecentSample).Result; // If right or wrong, tweak the display properties of the sample. This depends on the active mode. //DisplaySampleInfo(MostRecentSample); if (_userTrainingMode && MostRecentSample.RecognizedAsIndex >= 0) { var sc = MostRecentSample.RecognitionScore; var prefix = (sc < 1) ? "Arguably " : (sc < 1.5) ? "Maybe " : (sc < 2) ? "Probably " : (sc < 2.5) ? "Clearly " : (sc < 3) ? "Certainly " : "A perfect "; Speech.Say(prefix + MostRecentSample.RecognizedAsName); } else if (!_userTrainingMode) { if (CurrentCue == null) { CurrentCue = new ChoreographyCue(); } else if (MostRecentSample.RecognizedAsIndex == -1) { CurrentCue.Score = double.NaN; } else if (MostRecentSample.RecognizedAsIndex != MostRecentSample.TrueClassIndex) { CurrentCue.Score = -1 * MostRecentSample.RecognitionScore; CurrentCue.GestureClassIndex = MostRecentSample.RecognizedAsIndex; } //CuePrompter?.ReactToFinalizedGesture(MostRecentSample); else { var points = MostRecentSample.RecognitionScore; var delay = MostRecentSample.Metadata.Delay; CurrentCue.Score = points; CurrentCue.Delay = delay; } //if (!_singleMode) Choreographer?.ProceedWithNextCue(); MeleeChoreographer.SubmitResult(CurrentCue); } }
public override bool OnKeyUp([GeneratedEnum] Keycode keyCode, KeyEvent e) { if (keyCode == Keycode.VolumeDown || keyCode == Keycode.VolumeUp) { if (_collectingData) { lock (SelectedGestureClass) { // Respond to single-click events if (SingleClickWatch.Elapsed < ((MeleeChoreographer == null) ? TimeSpan.FromSeconds(0.5) : TimeSpan.FromSeconds(0.2))) { RelayToast("Single-clicked."); if (MeleeChoreographer == null) { AwaitChoreographer(); } else { MeleeChoreographer.Deactivate(); Task.Delay(100).Wait(); MeleeChoreographer = null; CurrentCue = default(ChoreographyCue); Speech.Say("Shutting down."); } // Either way, go no further handling this button-press (and discard the sequence unlooked-at). CurrentStage.Deactivate(); Stopwatch.Reset(); _collectingData = false; return(true); } //Log.Debug("MachineLearning", $"{keyCode} up"); if (MeleeChoreographer == null) { RelayToast("No choreographer."); _collectingData = false; return(true); // Long press without "Get Ready" first - ignore. } Task.Run(async() => { await Task.Delay(250); // Halt the gesture-collection stage and query it. var resultData = await CurrentStage.StopAndReturnResultsAsync(); //RelayToast("Evaluating."); var resultSeq = new Sequence <DKS>() { SourcePath = resultData }; var meta = CurrentStage.GetMetadata(GetAccelForDatapoint); meta.Delay = Delay; resultSeq.Metadata = meta; ResolveEndOfGesture(resultSeq); }); //if (_userTrainingMode) //{ // // Halt the gesture-collection stage and query it. // var resultData = CurrentStage.StopAndReturnResults(); // var resultSeq = new Sequence<DKS>() { SourcePath = resultData }; // resultSeq.Metadata = CurrentStage.GetMetadata(GetAccelForDatapoint); // ResolveEndOfGesture(resultSeq); //} //else if (_singleMode) //{ // Choreographer = new Choreographer(Dataset); // Choreographer.OnSendCue += async (o, eargs) => // { // await GimmeCue(eargs.Value); // Choreographer.Deactivate(); // }; // Choreographer.Activate(); //} //else if (!_seriesModeActive) //{ // Choreographer = new Choreographer(Dataset); // Choreographer.OnSendCue += async (o, eargs) => { await GimmeCue(eargs.Value); }; // Choreographer.Activate(); //} //else //{ // Choreographer?.Deactivate(); //} return(true); // Handled it, thanks. } } } return(base.OnKeyUp(keyCode, e)); }