4

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 party app).

I need to know whether the speech is finished or not. Are there any ideas on how to determine if any sound playing from sound card or not?

Chris Barlow
  • 3,174
  • 4
  • 28
  • 50
mefmef
  • 635
  • 2
  • 10
  • 23

3 Answers3

10

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.

CodingYourLife
  • 3,902
  • 3
  • 35
  • 54
Kent Aguilar
  • 3,760
  • 1
  • 27
  • 20
2

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.

L-Four
  • 11,965
  • 8
  • 52
  • 103
  • There's a whole bunch of meta discussions around link only answers - http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers. This is pretty poor as it stands. – Daniel Kelley May 23 '14 at 13:02
  • Well. The problem with that method is you are checking the master volume peak of the whole system. If there is for example playing music from another application, this method will fail. – Florian May 23 '14 at 18:05
1

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

Community
  • 1
  • 1
Florian
  • 5,728
  • 3
  • 41
  • 75