frgnca / AudioDeviceCmdlets

AudioDeviceCmdlets is a suite of PowerShell Cmdlets to control audio devices on Windows
MIT License
743 stars 92 forks source link

Feature request - Control individual applications like in Volume mixer #18

Open Suncatcher opened 6 years ago

Suncatcher commented 6 years ago

Does your cmdlet support getting info about apps that are currently active (=playing) in Windows Volume Mixer like this? I wanna list them and get info about their volume levels.

frgnca commented 6 years ago

@Suncatcher No, not at this point.

frgnca commented 6 years ago

@Suncatcher I have started the fork dev_v3.1_communicationDevice for this enhancement request. Until then, it IS possible with the current version to get the processID/processName, volume level, and mute state of the different applications under each audio device. This is just a workaround, but please see the following file https://github.com/frgnca/AudioDeviceCmdlets/blob/dev_volume-mixer/dev_volume-mixer.ps1

Suncatcher commented 6 years ago

Spectacular, man! Will check it soon.

Suncatcher commented 6 years ago

Well, I tried it and found out it's not working as it intended. Here is the output of dev_volume-mixer.ps1

App
Idle
Volume
100
Mute
False
########################

It shows Idle whilst in fact I have two apps active in mixer: System sounds and Chrome, and none of them has volume level 100.

image

frgnca commented 6 years ago

@Suncatcher How about with the file as it is now? Is the result the same with $deviceIndex=1 I think it was giving you the informations about the second AudioDevice which might have been the default recording device.

frgnca commented 6 years ago

@Suncatcher In fact, could you try the dll from the dev branch and tell me what you think? Get-AudioSession -List Here's what it looks like at this point image

Suncatcher commented 6 years ago

Well, it works not without glitches, but works and that's wonderful. About glitches: It shows wrong level, e.g. 38% on the screenshot, when in reality it's 21%. Also It shows Idle instead of system sounds.

sketch

But all that doesn't matter for me. Could you please build a single cmdlet for this function? E.g. GetMixerVolumes or smth like that? It's very cumbersome to type this script every time

$deviceIndex=1
########################
# Set $i to zero
$i=0

# While $i is less than the amount of audio session on the audio device
while($i -lt (Get-AudioDevice -Index $deviceIndex).Device.AudioSessionManager.Sessions.Count)
{
    Write-Host "########################"

    # Display audio session number
    Write-Host "Audio session #$($i + 1)"

    # Display processID of audio session
    Write-Host "Process name: $((Get-Process -Id (Get-AudioDevice -Index $deviceIndex).Device.AudioSessionManager.Sessions[$i].ProcessID).ProcessName)"

    # Display volume level of audio session
    Write-Host "Volume level: $(((Get-AudioDevice -Index $deviceIndex).Device.AudioSessionManager.Sessions[$i].SimpleAudioVolume.MasterVolume * 100).ToString('#'))%"

    # Display mute state of audio session
    Write-Host "Mute state:   $((Get-AudioDevice -Index $deviceIndex).Device.AudioSessionManager.Sessions[$i].SimpleAudioVolume.Mute)"

    # Increment $i
    $i++
}
Write-Host "########################"
Suncatcher commented 6 years ago

Also, is it possible to install your module not manually but via NuGet or some automated manner? In order to be up to date when your DLL is updated.

cdhunt commented 6 years ago

@Suncatcher We're working on getting the new version published to the PowerShell Gallery.

Old version: https://www.powershellgallery.com/packages/AudioDeviceCmdlets/

frgnca commented 6 years ago

@Suncatcher

It shows wrong level, e.g. 38% on the screenshot, when in reality it's 21%. Also It shows Idle instead of system sounds.

You're right. Those things have now been corrected in the dev dll. I found out later it's because the volume level of an audio channel that the CoreAudioApi gives is in relation to the current volume level of the audio device, unlike on the GUI where it is in relation to the maximum volume level.

As for being able to install the module not manually, I will get back to you once it is updated on the PowerShell Gallery.

Suncatcher commented 6 years ago

Thanks a ton!

frgnca commented 6 years ago

I can confirme the current v3.0 dll is now available from the PowerShell Gallery. When I merge in the finished volume mixer feature, I will update to v3.1 there.

PS> Save-Module -Name AudioDeviceCmdlets -Path <path> PS> Install-Module -Name AudioDeviceCmdlets

Suncatcher commented 6 years ago

I installed you module from PS Gallery exactly like above, but module commands are not recognized and in the exported commands I see nothing

image

Does it mean it was installed incorrectly?

frgnca commented 6 years ago

It probably means that I don't know how to properly publish to PS Gallery. I will definitely look into that when I have the time. Thank you for bringing this to my attention.

Suncatcher commented 6 years ago

Well, I assume this is not the problem of publishing, but the problem of incorrect installation. As I said, module commands are not recognized:

 PS C:\Users\User> Get-AudioDevice -List
 Get-AudioDevice : The term 'Get-AudioDevice' is not recognized as the name of a cmdlet, function, script file, or
 operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
 again.
 At line:1 char:1
 + Get-AudioDevice -List
 + ~~~~~~~~~~~~~~~
     + CategoryInfo          : ObjectNotFound: (Get-AudioDevice:String) [], CommandNotFoundException
     + FullyQualifiedErrorId : CommandNotFoundException

What has gone wrong? I just done

PS> Save-Module -Name AudioDeviceCmdlets -Path <path>
PS> Install-Module -Name AudioDeviceCmdlets
Suncatcher commented 6 years ago

Mmm, any suggestions? Tried to reinstall multiple times but module cmdlets are still not recognized.

Craefter commented 5 years ago

This link ain't working anymore: https://github.com/frgnca/AudioDeviceCmdlets/blob/dev_volume-mixer/AudioDeviceCmdlets.dll I was looking for a way to log at regular intervals the audio volume settings of devices and applications. Reason being: Users complain about seemingly randomly changing audio settings. So I was planning on some sort of script which would generate an output trigger either by time or some sort of application event. But, yeah, it seems like this dev tree has been deleted, am I correct?

frgnca commented 5 years ago

Correct. I still plan on adding this feature and merge it with future version v3.1 but I am currently in the process of moving places so I might not be able to code for this project for a bit.

Craefter commented 5 years ago

Do you still have that mentioned .dll for me to play around with until that time? :)

On Fri, Sep 21, 2018 at 3:31 PM frgnca notifications@github.com wrote:

Correct. I still plan on adding this feature and merge it with future version v3.1 but I am currently in the process of moving places so I might not be able to code for this project for a bit.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/frgnca/AudioDeviceCmdlets/issues/18#issuecomment-423531698, or mute the thread https://github.com/notifications/unsubscribe-auth/ApdNXHkIcCHZtZSDukgek4d4NtG57rVHks5udOoqgaJpZM4TMKJV .

smmalis37 commented 2 years ago

Any update here?

JuzioMiecio520 commented 1 year ago

Bump, any update? This feature would be awesome

Copy-link commented 1 year ago

Windows 10 (and presumably 11) has the ability to set what audio devices that individual apps listen to. For some reason, however, it resets often for me. If AudioDeviceCmdlets had the ability to set this, I could set up a script to run with Task Scheduler to make sure my apps are set correctly.

red-daut commented 4 months ago

I know this is over a year old, but I am very interested in having this added.

Any update on this?