'C# WinForms | Can I detect specific Sounds with a Microphone Input and let my program detect that specific sound and respond to it?

I'm currently trying to make a C# programm that simulates a Dial-Up Connection. So this what the programm should do:

When I play a DTMF Tone like 212 5678912 or the Phone Ring Signal from my phone, my Microphone should detect that sound and when the programm detects that sound it should do an action (here: create a value and play another sound) I do not play only DTMF Sounds! I play frequencies like from the Dial-Up!. Maybe the code looks like this:

if(sound from mic detected) do
{
 send variable to programm
 programm reacts
}

Is this somehow possible? It don't know anything about that subject :'( Thanks for any help! If this doesn't function with C# but with another language like Java or Python, then please tell me but i don't know how to add another language to a C# programm too ._. . Doesn't matter, thanks for any help!



Solution 1:[1]

To elaborate on @Jimi's link, this is pretty easy to do with NAudio and DtmfDetection.

using DtmfDetection.NAudio;
using NAudio.CoreAudioApi;
using NAudio.Wave;

static class Program
{
    static void Main(string[] args)
    {
        using var audioSource = new WasapiLoopbackCapture
        {
            ShareMode = AudioClientShareMode.Shared
        };

        using var analyzer = new BackgroundAnalyzer(audioSource);

        analyzer.OnDtmfDetected += dtmf => Console.WriteLine($"DTMF Detected: {dtmf}");

        _ = Console.ReadKey(intercept: true);
    }
}

More information: https://github.com/bert2/DtmfDetection

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matthew M.