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; } } } }
} // Analyzer_DtmfToneStopped private void cmdStop_Click(object sender, EventArgs e) { try { // logging MethodBase myMethod = new StackTrace().GetFrame(0).GetMethod(); MethodBeginLogging(myMethod); cmdStop.Enabled = false; cmdListen.Enabled = true; analyzer.StopCapturing(); StopIDTimerJob(); KillMumble(); // logging MethodEndLogging(myMethod); } // try catch (Exception ex) { UtilityMethods.ExceptionHandler(ex, TraceString); } // catch } // cmdStop_Click