How to know if a sound is playing using c#?

前端 未结 3 815
自闭症患者
自闭症患者 2020-12-19 17:39

I have a TTS program (Third Party) and I wrote a c# application that uses that program. (Type into my application and press a button to move the mouse and click on the Third

相关标签:
3条回答
  • 2020-12-19 18:03

    You could check whether the application emits sounds. Take a look at this: Getting individual windows application current volume output level as visualized in audio Mixer

    0 讨论(0)
  • You could use CSCore.
    Download it right here -> https://github.com/filoe/cscore

    Paste these lines on a console project.

    using System;
    using CSCore.CoreAudioAPI;
    
    namespace AudioDetector
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine(IsAudioPlaying(GetDefaultRenderDevice()));
                Console.ReadLine();
            }
    
            public static MMDevice GetDefaultRenderDevice()
            {
                using (var enumerator = new MMDeviceEnumerator())
                {
                    return enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
                }
            }
    
            public static bool IsAudioPlaying(MMDevice device)
            {
                using (var meter = AudioMeterInformation.FromDevice(device))
                {
                    return meter.PeakValue > 0;
                }
            }
        }
    }
    

    Play a music be it on YouTube, Music Player, etc...
    Run the program.
    It automatically notifies(true/false) if there is an audio currently being played or not.

    0 讨论(0)
  • 2020-12-19 18:14

    You can do this by using a wrapper around Direct X. There are many examples, just google for it. For example, C# code can be found here or here.

    0 讨论(0)
提交回复
热议问题