Author Topic: Discord Volume Control (Solved)  (Read 8208 times)

x-tremespeed

  • Newbie
  • *
  • Posts: 9
Discord Volume Control (Solved)
« on: November 14, 2019, 07:49:08 PM »
Hello!

I was wondering if anyone knows of a way to control Discord volume using VoiceAttack? I have been able to control other programs, but not Discord.

The issue is that Discord has 2 separate sliders in windows volume mixer, one for notifications etc. and one for voice chat. As you can probably guess, VoiceAttack only sees the notifications one (as that is the one that seems to be tied to the actual discord application window}.

I have tried changing the name of the discord window and the "notification" discord gets renamed the same thing in the volume mixer, but the other one, just named Discord, remains unchanged. I have tried doing another "change *Discord* to name blah blah" but it just renames the notification one again.
« Last Edit: November 16, 2019, 09:33:37 AM by x-tremespeed »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Discord Volume Control
« Reply #1 on: November 15, 2019, 11:08:37 AM »
Discord may use a separate process for voice audio, so you'd have to target that specifically.

If the process is a different instance under the same name (I.E. you have multiple Discord.exe processes), you'd have to target by process ID instead. Unfortunately the process ID will be different each time the process is launched, so you'd likely have to write an inline function to look it up.

x-tremespeed

  • Newbie
  • *
  • Posts: 9
Re: Discord Volume Control
« Reply #2 on: November 15, 2019, 12:39:05 PM »
Ah, you have set me on the right track. I managed to find the 4 PIDs Discord has, figured out which one controls the voice chat, and was able to control that one individually!

Unfortunately I have little to no experience with C# and I'm unsure how to retrieve PIDs using code. Do you have any idea how I can go about this? I'm not picky with singling out the single process to control - sending the volume controls to all 4 processes works for me!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Discord Volume Control
« Reply #3 on: November 15, 2019, 01:10:28 PM »
If you need the PID for all processes with the same name, this inline function should work:
Code: [Select]
using System.Diagnostics;

public class VAInline
{
public void main()
{
Process[] processes = Process.GetProcessesByName("Discord");


for (int i = 0; i < processes.Length;i++)
{
VA.SetInt("~process" + i, processes[i].Id);
}
}
}

It'll create an integer variable for each processes found, starting at 0 (E.G. "~process0", "~process1", "~process2", and "~process3").



A slightly more advanced command could use a loop to apply the volume setting to each process (rather than using four different "Set Audio Level" actions), without having to specify the amount of processes (in case there are more or fewer than four at some point).

E.G.
Code: [Select]
Inline C# Function: Get PIDs, wait until execution finishes
Start Loop : Repeat From 0 to [{INT:~totalProcesses}]
    Toggle mute for application [{INT:~process{INT:~i}}] audio
End Loop

Where "Get PIDs" contains
Code: [Select]
using System.Diagnostics;

public class VAInline
{
public void main()
{
Process[] processes = Process.GetProcessesByName("Discord");


for (int i = 0; i < processes.Length;i++)
{
VA.SetInt("~process" + i, processes[i].Id);
}

VA.SetInt("~totalProcesses", processes.Length - 1);
}
}
« Last Edit: March 02, 2022, 03:57:26 PM by Pfeil »

x-tremespeed

  • Newbie
  • *
  • Posts: 9
Re: Discord Volume Control
« Reply #4 on: November 15, 2019, 02:04:45 PM »
I'm having a bit of trouble - I put in your code and am getting "Unable to set application audio: {INT:~process{INT:~i}}" 4 times in the log. I added a write to log line in the loop and got this:

Code: [Select]
Inline C# Function: Get PIDs, wait until execution finishes
Start Loop : Repeat From 0 to [{INT:~totalProcesses}]
    Toggle mute for application [{INT:~process{INT:~i}}] audio
    Write [Purple] '{INT:~process{INT:~i}}' to log
End Loop

3:56:35 PM - Not set
3:56:35 PM - Unable to set application audio: {INT:~process{INT:~i}}
3:56:34 PM - Not set
3:56:34 PM - Unable to set application audio: {INT:~process{INT:~i}}
3:56:34 PM - Not set
3:56:34 PM - Unable to set application audio: {INT:~process{INT:~i}}
3:56:34 PM - Not set
3:56:34 PM - Unable to set application audio: {INT:~process{INT:~i}}

And here is the inline C# function, copied right from my code:

Code: [Select]
using System.Diagnostics;

public class VAInline
{
public void main()
{

Process[] processes = Process.GetProcessesByName("Discord");


for (int i = 0; i < processes.Length;i++)
{
VA.SetInt("~process" + i, processes[i].Id);
}

VA.SetInt("~totalProcesses", processes.Length - 1);
}
}

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Discord Volume Control
« Reply #5 on: November 15, 2019, 02:06:07 PM »
Did you add the indexer ("~i") to the for loop?

x-tremespeed

  • Newbie
  • *
  • Posts: 9
Re: Discord Volume Control
« Reply #6 on: November 15, 2019, 02:29:20 PM »
Ah, there we go - it's all fixed and working perfectly now!

I knew it would be something I was missing. ::)

Thank you very much for all your help. I really appreciate it!

My buddy recently got a new headset with a built in chat/game mixer and I thought that would be such a cool thing to have and I started looking around for how to achieve this from a software point of view. I fairly recently got VoiceAttack and, having forgotten about the mixer idea, found the sound control options and I set out on my quest again! I don't think I'll go as deep as replicating exactly how a mixer operates, but being able to control my voice chatting software separately from the rest of my computer is a good enough compromise for me.

Thank you, again, for helping me with this!  ;D

Malic

  • Full Member
  • ***
  • Posts: 105
Re: Discord Volume Control (Solved)
« Reply #7 on: March 02, 2022, 03:53:30 PM »
Having the same issue, wanting a volume control for discord.

Was a VAP file made that just works, because I cant seem to get it to work, even with the ~ in the loop from the lastest posts.  Not sure if discord changed its behavior since this was writted in 2019, I know it had something where its title changed depending on what tab you had selected a few years ago

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Discord Volume Control (Solved)
« Reply #8 on: March 02, 2022, 05:28:11 PM »
Do you have a screenshot of the configuration window for your "Loop Start - Repeat a Certain Number of Times" action?

Do you have the "Write a Value to the Event Log" action in your loop? If so, are you seeing that writing to the log when the command is executed?

Malic

  • Full Member
  • ***
  • Posts: 105
Re: Discord Volume Control (Solved)
« Reply #9 on: March 18, 2022, 06:30:32 AM »
Is direct copy and paste from the examples above






Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Discord Volume Control (Solved)
« Reply #10 on: March 18, 2022, 09:50:25 AM »
Do you have a screenshot of the configuration window for your "Loop Start - Repeat a Certain Number of Times" action?