예제 #1
0
        private static LiveAudioDtmfAnalyzer InitLiveAudioAnalyzer(IWaveIn waveIn)
        {
            var analyzer = new LiveAudioDtmfAnalyzer(waveIn);

            analyzer.DtmfToneStarted += start => Console.WriteLine($"{start.DtmfTone.Key}");
            return(analyzer);
        }
예제 #2
0
        }     // cmdStop_Click

        private void cmdUseDevices_Click(object sender, EventArgs e)
        {
            try
            {
                // logging
                MethodBase myMethod = new StackTrace().GetFrame(0).GetMethod();
                MethodBeginLogging(myMethod);

                DeviceInNo  = (int)comboWaveIn.SelectedValue;
                DeviceOutNo = (int)comboWaveOut.SelectedValue;

                SetText(string.Format("DeviceIn set to {0} -- DeviceOut set to {1}", DeviceInNo.ToString(), DeviceOutNo.ToString()));

                micIn.BufferMilliseconds = 100;
                micIn.NumberOfBuffers    = 3;
                micIn.DeviceNumber       = DeviceInNo;

                MyState = DTMFCommandStates.ignore;
                SpeakIt("Welcome to Rumble!");
                LoadConfig("0");

                analyzer = new LiveAudioDtmfAnalyzer(micIn, forceMono: false);
                analyzer.DtmfToneStarted += Analyzer_DtmfToneStarted;
                analyzer.DtmfToneStopped += Analyzer_DtmfToneStopped;
                cmdListen.Enabled         = true;

                // logging
                MethodEndLogging(myMethod);
            } // try
            catch (Exception ex)
            {
                UtilityMethods.ExceptionHandler(ex, TraceString);
            } // catch
        }     // cmdUseDevices_Click
예제 #3
0
        private static LiveAudioDtmfAnalyzer InitLiveAudioAnalyzer(Log log, IWaveIn waveIn)
        {
            var analyzer = new LiveAudioDtmfAnalyzer(waveIn);

            analyzer.DtmfToneStarted += start => log.Add($"{start.DtmfTone.Key} key started on {start.Position.TimeOfDay} (channel {start.Channel})");
            analyzer.DtmfToneStopped += end => log.Add($"{end.DtmfTone.Key} key stopped after {end.Duration.TotalSeconds} s (channel {end.Channel})");
            return(analyzer);
        }
예제 #4
0
        private static void CaptureAndAnalyzeLiveAudio()
        {
            using (var log = new Log("audioOut.log"))
            {
                LiveAudioDtmfAnalyzer analyzer = null;
                IWaveIn audioSource            = null;

                while (true)
                {
                    Console.WriteLine("====================================\n"
                                      + "[O]   Capture current audio output\n"
                                      + "[M]   Capture mic in\n"
                                      + "[Esc] Stop capturing/quit");
                    var key = Console.ReadKey(true);

                    switch (key.Key)
                    {
                    case ConsoleKey.O:
                        analyzer?.StopCapturing();
                        audioSource?.Dispose();

                        audioSource = new WasapiLoopbackCapture {
                            ShareMode = AudioClientShareMode.Shared
                        };
                        analyzer = InitLiveAudioAnalyzer(log, audioSource);
                        analyzer.StartCapturing();

                        break;

                    case ConsoleKey.M:
                        analyzer?.StopCapturing();
                        audioSource?.Dispose();

                        audioSource = new WaveInEvent {
                            WaveFormat = new WaveFormat(8000, 32, 1)
                        };
                        analyzer = InitLiveAudioAnalyzer(log, audioSource);
                        analyzer.StartCapturing();

                        break;

                    case ConsoleKey.Escape:
                        if (analyzer == null || !analyzer.IsCapturing)
                        {
                            return;
                        }

                        analyzer.StopCapturing();
                        audioSource.Dispose();

                        break;
                    }
                }
            }
        }
예제 #5
0
        public void Start(IWaveIn waveIn)
        {
            var config = new DetectorConfig();

            config.PowerThreshold = _config.Tolerance;

            var analyzer = new LiveAudioDtmfAnalyzer(config, waveIn);

            //analyzer.DtmfToneStarted += start => _log.Add($"{start.DtmfTone.Key} key started on {start.Position.TimeOfDay} (channel {start.Channel})");
            //analyzer.DtmfToneStopped += end => _log.Add($"{end.DtmfTone.Key} key stopped after {end.Duration.TotalSeconds}s (channel {end.Channel})");

            analyzer.DtmfToneStarted += start =>
            {
                EvaluatorStarted?.Invoke(this, new EvaluatorEventArgs(start, null, DateTime.UtcNow));
            };

            analyzer.DtmfToneStopped += end =>
            {
                _logger.Debug($"AudioEvaluator->DtmfToneStopped {end.TimeStamp.ToString("O")}");

                EvaluatorFinished?.Invoke(this, new EvaluatorEventArgs(null, end, DateTime.UtcNow));

                if (end.Duration > new TimeSpan(0, 0, 0, 0, 0))
                {
                    _logger.Debug($"AudioEvaluator->Finished Tones: {_finishedTones.Count}");

                    _logger.Debug($"AudioEvaluator->Current Finished Tones:");
                    _logger.Debug($"----------------------------------------------------------");

                    lock (_lock)
                    {
                        foreach (var tone in _finishedTones)
                        {
                            _logger.Debug(
                                $"AudioEvaluator->Finished Tone: {tone.DtmfTone.HighTone} finished in {tone.Duration.TotalMilliseconds}ms");
                        }
                    }

                    _logger.Debug($"==========================================================");

                    var existingTone = _finishedTones.FirstOrDefault(x => x.DtmfTone.HighTone == end.DtmfTone.HighTone &&
                                                                     (end.TimeStamp.Subtract(x.TimeStamp).TotalMilliseconds <= 1000 &&
                                                                      end.TimeStamp.Subtract(x.TimeStamp).TotalMilliseconds >= -1000));

                    if (existingTone != null && existingTone.Duration < new TimeSpan(0, 0, 0, 0, 1500))
                    {
                        _logger.Debug($"AudioEvaluator->DtmfToneStopped: Existing tone for {existingTone.DtmfTone.HighTone} adding {end.Duration.TotalMilliseconds}ms");
                        existingTone.Duration += end.Duration;
                    }
                    else
                    {
                        _logger.Debug($"AudioEvaluator->DtmfToneStopped: No Existing tone for {end.DtmfTone.HighTone} for duration {end.Duration}");
                        _finishedTones.Add(end);
                    }
                }

                CheckFinishedTonesForTriggers();
            };

            analyzer.StartCapturing();
        }