private void SendSpeechRequest(output_data data) { WebClient webClient = new WebClient(); webClient.QueryString.Add("query", data.query); webClient.QueryString.Add("uid", data.uid); webClient.QueryString.Add("reset", data.reset); string result = webClient.DownloadString("http://marko-backend.herokuapp.com/handle_voice"); synth.SpeechSynthesizer synthesizer = new synth.SpeechSynthesizer(); synthesizer.SpeakAsync(result); }
void sre_SpeechRecognized(object sender, recog.SpeechRecognizedEventArgs e) { synth.SpeechSynthesizer synthesizer = new synth.SpeechSynthesizer(); output_data output = new output_data(); output.uid = "*****@*****.**"; Console.WriteLine(e.Result.Text); bool matchingQuery = dictionary.Any(e.Result.Text.Contains); if (matchingQuery) { output.query = e.Result.Text; output.reset = "false"; SendSpeechRequest(output); } }
/// <summary> /// Handles recognition complete events /// </summary> private void Engine_RecognitionComplete(object sender, RecognitionResult e) { TrackedFace face = null; if (e.Faces != null) face = e.Faces.FirstOrDefault(); using (var processedBitmap = (Bitmap)e.ColorSpaceBitmap.Clone()) { if (face == null) { this.viewModel.ReadyForTraining = false; } else { using (var g = Graphics.FromImage(processedBitmap)) { var isFmb = this.viewModel.ProcessorType == ProcessorTypes.FaceModel; var rect = face.TrackingResult.FaceRect; var faceOutlineColor = Color.Green; if (isFmb) { if (face.TrackingResult.ConstructedFaceModel == null) { faceOutlineColor = Color.Red; if (face.TrackingResult.BuilderStatus == FaceModelBuilderCollectionStatus.Complete) faceOutlineColor = Color.Orange; } var scale = (rect.Width + rect.Height) / 6; var midX = rect.X + (rect.Width / 2); var midY = rect.Y + (rect.Height / 2); if ((face.TrackingResult.BuilderStatus & FaceModelBuilderCollectionStatus.LeftViewsNeeded) == FaceModelBuilderCollectionStatus.LeftViewsNeeded) g.FillRectangle(new SolidBrush(Color.Red), rect.X - (scale * 2), midY, scale, scale); if ((face.TrackingResult.BuilderStatus & FaceModelBuilderCollectionStatus.RightViewsNeeded) == FaceModelBuilderCollectionStatus.RightViewsNeeded) g.FillRectangle(new SolidBrush(Color.Red), rect.X + rect.Width + (scale * 2), midY, scale, scale); if ((face.TrackingResult.BuilderStatus & FaceModelBuilderCollectionStatus.TiltedUpViewsNeeded) == FaceModelBuilderCollectionStatus.TiltedUpViewsNeeded) g.FillRectangle(new SolidBrush(Color.Red), midX, rect.Y - (scale * 2), scale, scale); if ((face.TrackingResult.BuilderStatus & FaceModelBuilderCollectionStatus.FrontViewFramesNeeded) == FaceModelBuilderCollectionStatus.FrontViewFramesNeeded) g.FillRectangle(new SolidBrush(Color.Red), midX, midY, scale, scale); } this.viewModel.ReadyForTraining = faceOutlineColor == Color.Green; ////Output for face recognition if (!check_ini) { check_ini = true; output_data output = new output_data(); output.query = "_"; output.uid = "*****@*****.**"; output.reset = "true"; SendSpeechRequest(output); } g.DrawPath(new Pen(faceOutlineColor, 5), face.TrackingResult.GetFacePath()); if (!string.IsNullOrEmpty(face.Key)) { var score = Math.Round(face.ProcessorResults.First().Score, 2); // Write the key on the image... g.DrawString(face.Key + ": " + score, new Font("Arial", 100), Brushes.Red, new System.Drawing.Point(rect.Left, rect.Top - 25)); SpeechToText(); } } if (this.takeTrainingImage) { var eoResult = (EigenObjectRecognitionProcessorResult)face.ProcessorResults.SingleOrDefault(x => x is EigenObjectRecognitionProcessorResult); var fmResult = (FaceModelRecognitionProcessorResult)face.ProcessorResults.SingleOrDefault(x => x is FaceModelRecognitionProcessorResult); var bstf = new BitmapSourceTargetFace(); bstf.Key = this.viewModel.TrainName; if (eoResult != null) { bstf.Image = (Bitmap)eoResult.Image.Clone(); } else { bstf.Image = face.TrackingResult.GetCroppedFace(e.ColorSpaceBitmap); } if (fmResult != null) { bstf.Deformations = fmResult.Deformations; bstf.HairColor = fmResult.HairColor; bstf.SkinColor = fmResult.SkinColor; } this.viewModel.TargetFaces.Add(bstf); this.SerializeBitmapSourceTargetFace(bstf); this.takeTrainingImage = false; this.UpdateTargetFaces(); } } this.viewModel.CurrentVideoFrame = LoadBitmap(processedBitmap); } // Without an explicit call to GC.Collect here, memory runs out of control :( GC.Collect(); }