protected void TrackPitch(RecognitionResult rr) { if (rr.Audio == null) { return; } using (MemoryStream audioStream = new MemoryStream()) { rr.Audio.WriteToWaveStream(audioStream); audioStream.Position = 0; byte[] audioBytes = audioStream.ToArray(); float[] audioBuffer = new float[audioBytes.Length / 2]; for (int i = 0, j = 0; i < audioBytes.Length / 2; i += 2, j++) { // convert two bytes to one short short s = BitConverter.ToInt16(audioBytes, i); // convert to range from -1 to (just below) 1 audioBuffer[j] = s / 32768.0f; } // Reset tracker.Reset(); pitch.Clear(); // Process tracker.ProcessBuffer(audioBuffer); // Notify WSRProfileManager.GetInstance().UpdatePitch(pitch.Mean()); } }
private void DrawProfile() { var current = WSRProfileManager.GetInstance().Current; var profiles = WSRProfileManager.GetInstance().Profiles; for (int i = 0; i < profiles.Count && i < 5; i++) { WSRProfile profile = profiles[i]; if (profile == null) { continue; } var label = ((TextBlock)System.Windows.LogicalTreeHelper.FindLogicalNode(this, "label_Profile" + i)); label.Text = profile.Name; label.Foreground = (profile == current) ? red : black; ((TextBlock)System.Windows.LogicalTreeHelper.FindLogicalNode(this, "label_Pitch" + i)).Text = "Pitch: " + Math.Round(profile.Pitch); ((TextBlock)System.Windows.LogicalTreeHelper.FindLogicalNode(this, "label_Mood" + i)).Text = "Mood: " + profile.Mood; ((TextBlock)System.Windows.LogicalTreeHelper.FindLogicalNode(this, "label_Height" + i)).Text = "Height: " + profile.Height; ((TextBlock)System.Windows.LogicalTreeHelper.FindLogicalNode(this, "label_Head" + i)).Text = "Head: " + Math.Round(profile.x / 10) + "," + Math.Round(profile.y / 10) + "," + Math.Round(profile.z / 10); } if (null != current) { label_Gesture.Text = "Head: Tracked x: " + Math.Round(current.x / 10) + " y: " + Math.Round(current.y / 10) + " z: " + Math.Round(current.z / 10); label_Height.Text = "Height: " + current.Height + "m"; } }
public static WSRProfileManager GetInstance() { if (manager == null) { manager = new WSRProfileManager(); } return(manager); }
protected String HandleHeight(XPathNavigator xnav, String path) { XPathNavigator height = xnav.SelectSingleNode("/SML/action/@height"); if (height != null) { double h = WSRProfileManager.GetInstance().Heigth; WSRSpeakerManager.GetInstance().Speak(h + " mètres", false); } return(path); }
private async Task FaceRecognitionAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token) { if (interval.TotalMilliseconds == 0) { return; } TimeSpan threshold = WSRConfig.GetInstance().FaceTH; // Initial wait time before we begin the periodic loop. if (dueTime > TimeSpan.Zero) { await Task.Delay(dueTime, token); } DateTime LocalTimestamp = Timestamp; // Repeat this loop until cancelled. while (!token.IsCancellationRequested) { // Skip already work with given data if (Timestamp == LocalTimestamp) { await Task.Delay(interval, token); continue; } // Timestamp data LocalTimestamp = Timestamp; FaceRecoWatch.Again(); // Do Job try { var names = FaceManager.Recognize(); if (null != names) { WSRProfileManager.GetInstance().UpdateFace(names); } } catch (Exception ex) { WSRConfig.GetInstance().logError("FACE", ex); } FaceRecoWatch.Stop(); // Wait to repeat again. if (interval > TimeSpan.Zero) { await Task.Delay(interval, token); } } }
public bool Speak(String tts, bool async) { // Run Async if (async) { return(SpeakAsync(tts)); } // Compute name var name = WSRProfileManager.GetInstance().CurrentName(); tts = Regex.Replace(tts, "\\[name\\]", name, RegexOptions.IgnoreCase); WSRConfig.GetInstance().logInfo("TTS", "Try speaking ... " + tts); lock (Lock) { // Prevent multiple Speaking if (Speaking || working) { WSRConfig.GetInstance().logInfo("TTS", "Already speaking ... enqueue"); queue.Enqueue(tts); return(false); } working = true; } // Run all speech in a list of Task List <Task> latest = new List <Task>(); SpeechBuffer += tts + " "; foreach (var speaker in speakers) { latest.Add(Task.Factory.StartNew(() => speaker.Speak(tts))); } // Wait for end of Tasks foreach (var task in latest) { task.Wait(); } latest.Clear(); lock (Lock) { working = false; } WSRConfig.GetInstance().logInfo("TTS", "End speaking"); // Dequeue next (always async ...) if (queue.Count > 0) { Speak(queue.Dequeue(), true); } return(true); }
public void SendRequest(string url) { if (url == null) { return; } if (working) { return; } working = true; // Clean URL url = CleanURL(url); // Append ClientId url = AppendURL(url, "client", WSRConfig.GetInstance().Id); // Append UserId var profile = WSRProfileManager.GetInstance().Current; if (null != profile) { url = AppendURL(url, "profile", profile.Name); } // Append Directory Path url = AppendURL(url, "directory", WSRSpeechManager.GetInstance().GetGrammarPath()); WSRConfig.GetInstance().logInfo("HTTP", "Build HttpRequest: " + url); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "GET"; WSRConfig.GetInstance().logInfo("HTTP", "Send HttpRequest: " + req.Address); try { HttpWebResponse res = (HttpWebResponse)req.GetResponse(); using (StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8)) { WSRSpeakerManager.GetInstance().Speak(sr.ReadToEnd(), false); } } catch (WebException ex) { WSRConfig.GetInstance().logError("HTTP", ex); } working = false; }
protected void Prefetch(Skeleton sk) { // Store head in milimeters like depth var head = sk.Joints[JointType.Head]; if (head.TrackingState == JointTrackingState.Tracked) { var pos = head.Position; WSRProfileManager.GetInstance().UpdateHead(pos.X * 1000f, pos.Y * 1000f, pos.Z * 1000f); } // Store height in m Joint p1 = sk.Joints[JointType.ElbowLeft]; Joint p2 = sk.Joints[JointType.WristLeft]; if (p1.TrackingState == JointTrackingState.Tracked && p2.TrackingState == JointTrackingState.Tracked) { var height = Math.Round((SkeletalExtensions.Length(p1, p2) * 100 * 5.27 + 6 + 42.05) / 100, 2); WSRProfileManager.GetInstance().UpdateHeight(height); } }
private async Task FaceTrackingAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token) { if (interval.TotalMilliseconds == 0) { return; } // Initial wait time before we begin the periodic loop. if (dueTime > TimeSpan.Zero) { await Task.Delay(dueTime, token); } DateTime LocalTimestamp = Timestamp; FaceTracker tracker = new FaceTracker(Sensor); // Repeat this loop until cancelled. while (!token.IsCancellationRequested) { // Skip already work with given data if (Timestamp == LocalTimestamp) { await Task.Delay(interval, token); continue; } // Timestamp data LocalTimestamp = Timestamp; FaceTrackWatch.Again(); // Do Job try { CopyColorData = true; CopySkeletons = true; FPoints = null; Mood = 0; if (null != GestureManager && null != GestureManager.Skeleton) { FaceTrackFrame frame = tracker.Track(ColorFormat, ColorData, DepthFormat, DepthData, GestureManager.Skeleton); if (frame.TrackSuccessful) { // Only once. It doesn't change. if (FTriangles == null) { FTriangles = frame.GetTriangles(); } FPoints = frame.GetProjected3DShape(); Mood = frame.GetAnimationUnitCoefficients()[AnimationUnit.LipCornerDepressor]; WSRProfileManager.GetInstance().UpdateMood(Mood); } } } catch (Exception ex) { WSRConfig.GetInstance().logError("FACE", ex); } FaceTrackWatch.Stop(); // Wait to repeat again. if (interval > TimeSpan.Zero) { await Task.Delay(interval, token); } } // Dispose Tracker tracker.Dispose(); }
public static WSRProfileManager GetInstance() { if (manager == null) { manager = new WSRProfileManager(); } return manager; }
// ========================================== // HANDLE HTTPSERVER // ========================================== public override bool HandleCustomRequest(NHttp.HttpRequestEventArgs e, StreamWriter writer) { if (base.HandleCustomRequest(e, writer)) { return(true); } // Parse Result's Photo if (e.Request.Params.Get("picture") != null) { String path = ActiveSensor().TakePicture("medias/"); e.Response.ContentType = "image/jpeg"; Bitmap bmp = (Bitmap)Bitmap.FromFile(path); bmp.Save(e.Response.OutputStream, ImageFormat.Jpeg); return(true); } // Return Last Height Active Sensor var height = e.Request.Params.Get("height"); if (height != null) { double h = WSRProfileManager.GetInstance().Heigth; if (height == "tts") { WSRSpeakerManager.GetInstance().Speak(h + " mètres", false); } else { writer.Write("" + h); } return(true); } // Face recognition String facereco = e.Request.Params.Get("face"); if (facereco != null) { facereco = e.Server.HtmlDecode(facereco); if ("start".Equals(facereco)) { WSRConfig.GetInstance().StandByFace = false; } else if ("stop".Equals(facereco)) { WSRConfig.GetInstance().StandByFace = true; } } // Gesture recognition String gesture = e.Request.Params.Get("gesture"); if (gesture != null) { gesture = e.Server.HtmlDecode(gesture); if ("start".Equals(gesture)) { WSRConfig.GetInstance().StandByGesture = false; } else if ("stop".Equals(gesture)) { WSRConfig.GetInstance().StandByGesture = true; } } return(false); }