1

I'm looking for the current actual output levels, not what the volume is set to.

Ideally this would be a command-line tool, but if there's so way I could generate one myself with APIs, that would also be acceptable.

2
  • expressed how? decibels? Jun 22, 2015 at 15:05
  • percent is what i was going for Jun 22, 2015 at 15:35

2 Answers 2

2

I kept searching and was able to cobble together a command-line app to do this myself:

using System;
using System.Collections.Generic;
using CSCore.CoreAudioAPI;
using System.Diagnostics;
using System.Web.Script.Serialization;

namespace VolumeLevel
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
            {
                using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
                {
                    IDictionary<string, float> procs = new Dictionary<string, float>();
                    foreach (var session in sessionEnumerator)
                    {
                        using (var audioMeterInformation = session.QueryInterface<AudioMeterInformation>())
                        using (var session2 = session.QueryInterface<AudioSessionControl2>())
                        {
                            if (session2.ProcessID > 0 && audioMeterInformation != null) procs[session2.Process.MainWindowTitle] = audioMeterInformation.GetPeakValue();
                        }
                    }
                    if (procs.Count > 0)
                    {
                        Console.WriteLine(new JavaScriptSerializer().Serialize(procs));
                    } else
                    {
                        Console.WriteLine("{}");
                    }
                    Environment.Exit(0);
                }
            }
        }

        private static AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
        {
            using (var enumerator = new MMDeviceEnumerator())
            {
                using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
                {
                    Debug.WriteLine("DefaultDevice: " + device.FriendlyName);
                    var sessionManager = AudioSessionManager2.FromMMDevice(device);
                    return sessionManager;
                }
            }
        }
    }
}

The output will be something like this:

{"Spotify Premium":0.8345225}

This requires the CSCore library, which you can get here, and you'll need to add a reference to System.Web.Extensions for the JSON output.

0

As there are no such programs for this task, I compiled a program written by ultimatebrent.

You can download it here: https://github.com/TheTitanrain/wov/releases

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .