/// <summary> /// Mic array beam direction changed event handler /// </summary> /// <param name="beamDirectionChanged"></param> private void BeamDirectionChangedHandler(sr.BeamDirectionChanged beamDirectionChanged) { // KinectAudioSource.BeamAngle Property // Gets the beam angle (in degrees), which is the direction the audio beam is pointing. // The center value is zero, negative values are right of the Kinect device (left of user), and positive values are left of the Kinect device (right of user). int angle = Direction.to180fromRad(-beamDirectionChanged.Body.Angle); Tracer.Trace("beam direction changed at " + angle); // register the fact: _state.SoundBeamDirection = angle; _state.SoundBeamTimeStamp = DateTime.Now; //setPan(angle); //setTilt(0); }
/// <summary> /// Speech recognition rejected handler /// </summary> /// <param name="rejected"></param> private void SpeechRecognitionRejectedHandler(sr.SpeechRecognitionRejected rejected) { TimeSpan sinceTalk = DateTime.Now - Talker.lastSpoken; if (sinceTalk.TotalSeconds < SpeechRecognizerTalkerBlackoutSec) { Tracer.Trace("SpeechRecognitionRejectedHandler in blackout at " + sinceTalk.TotalSeconds + " sec"); return; } int angle = Direction.to180fromRad(-rejected.Body.Angle); Tracer.Trace("speech not recognized at " + angle); //Talker.Say(10, "What?"); }
/// <summary> /// Speech recognized handler /// </summary> /// <param name="recognized"></param> private void SpeechRecognizedHandler(sr.SpeechRecognized recognized) { TimeSpan sinceTalk = DateTime.Now - Talker.lastSpoken; if (sinceTalk.TotalSeconds < SpeechRecognizerTalkerBlackoutSec) { Tracer.Trace("SpeechRecognizedHandler in blackout at " + sinceTalk.TotalSeconds + " sec"); return; } int angle = Direction.to180fromRad(-recognized.Body.Angle); string commandText = recognized.Body.Text; string commandSemantics = recognized.Body.Semantics.ValueString; double confidence = Math.Round(recognized.Body.Confidence, 3); // 0 to 1, usually around 0.97 for successfully recognized commands //Tracer.Trace("**************************************** SpeechRecognizedHandler **************************************** "); //Tracer.Trace("speech '" + commandText + "'=>'" + commandSemantics + "' at " + angle + " degrees, confidence " + confidence); // find the handler based on semantics: SpeechRecognizerDictionaryItem srdi = (from di in speechRecognizerDictionary where di.semantics == commandSemantics select di).FirstOrDefault(); // usually Confidence is 0.95-0.99 if (srdi != null && recognized.Body.Confidence > srdi.minimumRequiredConfidence) { VoiceCommandState state = _state.VoiceCommandState; state.TimeStamp = DateTime.Now; state.Text = commandText; state.Semantics = commandSemantics; state.ConfidencePercent = (int)Math.Round(confidence * 100.0f); state.Direction = angle; LogHistory(1, "speech '" + commandText + "'=>'" + commandSemantics + "' at " + angle + " deg, " + confidence); // now call the handler: srdi.handler(srdi, angle); } else if (confidence > 0.5d) { LogHistory(3, "rejected '" + commandText + "'=>'" + commandSemantics + "' at " + angle + " deg, " + confidence); Talker.Say(10, "Homm"); // not enough confidence } //setPan(angle); //setTilt(0); }
/// <summary> /// Speech detected handler /// </summary> /// <param name="detected"></param> private void SpeechDetectedHandler(sr.SpeechDetected detected) { TimeSpan sinceTalk = DateTime.Now - Talker.lastSpoken; if (sinceTalk.TotalSeconds < SpeechRecognizerTalkerBlackoutSec) { Tracer.Trace("SpeechDetectedHandler in blackout at " + sinceTalk.TotalSeconds + " sec"); return; } int angle = Direction.to180fromRad(-detected.Body.Angle); Tracer.Trace("speech detected at " + angle); // register the fact: _state.AnySpeechDirection = angle; _state.AnySpeechTimeStamp = DateTime.Now; //setPan(angle); //setTilt(0); //Talker.Say(10, "" + ((int)angle)); }