示例#1
0
        public void Record()
        {
            // We need to check the microphone is working
            // And we should only record x time for messages
            // If the user is going to record a new message it must overrite something.
            if (WaveIn.DeviceCount == 0)
            {
                _listBox.AddItemThreadSafe("Cant find microphone");
                return;
            }

            var timeRecorded = HowMuchTimeRecorded();

            if (timeRecorded.TotalSeconds <= MaxTimeSpanInSeconds - 10)
            {
                _listBox.AddItemThreadSafe($"{MaxTimeSpanInSeconds - timeRecorded.TotalSeconds} seconds left to record.");
                _listBox.AddItemThreadSafe("Say what you want, press but again to stop");

                _timer           = new System.Timers.Timer(MaxTimeSpanInMilliseconds - timeRecorded.TotalMilliseconds);
                _timer.AutoReset = false;
                _timer.Elapsed  += ForceStop;

                _waveSource = new WaveInEvent
                {
                    WaveFormat = new WaveFormat(44100, 1)
                };

                var    fileName      = Guid.NewGuid();
                string _tempFilename = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), $@"..\..\Voice\SavedVoices\{fileName}.wav"));

                _waveSource.DataAvailable    += DataAvailable;
                _waveSource.RecordingStopped += RecordingStopped;
                _waveWriter = new WaveFileWriter(_tempFilename, _waveSource.WaveFormat);

                _waveSource.StartRecording();

                _timer.Start();
            }
            else
            {
                _listBox.AddItemThreadSafe("Your out of space");
            }
        }
示例#2
0
        public void ProcessFrameEverySecond()
        {
            using (var frame = new Mat())
            {
                _videoCapture.Retrieve(frame, 0);

                if (AutoDetect)
                {
                    using (FaceDetection faceDetector = new FaceDetection())
                    {
                        var foundFace = faceDetector.DetectFace(frame);
                        if (foundFace)
                        {
                            _listBox.AddItemThreadSafe(_handlePhrases.GetSaying());
                        }
                        else
                        {
                            _listBox.AddItemThreadSafe("I didn't find you!!");
                        }
                    }
                }
            }
        }