Author Topic: Save the current speaker volume, and then set it's volume back?  (Read 748 times)

Snacko

  • Newbie
  • *
  • Posts: 12
I am trying to lower my speakers when I PTT, and then reset the volume to where it was.
I can Mute and unMute, but I just want to lower it and then restore it. 
And I have tried setting it to a fixed value of 30, then restore it to 100%, but that was too loud.  I would then have to adjust a lot of other devices...

If I could just save the current volume to a variable, then restore it, that would be perfect.

And Ideas??   :-\
Thanks

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4780
  • RTFM
Re: Save the current speaker volume, and then set it's volume back?
« Reply #1 on: June 02, 2024, 12:20:54 AM »
If the device is the Windows default multimedia playback device, the "{STATE_SYSVOL}" token returns the volume setting of said device.


If it isn't, you could try using the "Offset" option of the "Set Audio Level" action, keeping in mind that the offset would always need to be smaller than the lowest volume setting you use (as otherwise the restored volume will be the offset, as volume can't be negative so it'd offset from 0)

iceblast

  • Sr. Member
  • ****
  • Posts: 374
Re: Save the current speaker volume, and then set it's volume back?
« Reply #2 on: June 10, 2024, 07:16:40 PM »
Code: [Select]
Set integer [Volume] value to the converted value of {STATE_SYSVOL}
Start Loop While :  Keyboard Key 'F22' Is Pressed
    Pause a variable number of seconds [0.1]
    Set default playback device volume to [1]
    Pause a variable number of seconds [0.1]
End Loop
Set default playback device volume to [{INT:Volume}]

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4780
  • RTFM
Re: Save the current speaker volume, and then set it's volume back?
« Reply #3 on: June 11, 2024, 12:31:23 AM »
Code: [Select]
Set integer [Volume] value to the converted value of {STATE_SYSVOL}
Start Loop While :  Keyboard Key 'F22' Is Pressed
    Pause a variable number of seconds [0.1]
    Set default playback device volume to [1]
    Pause a variable number of seconds [0.1]
End Loop
Set default playback device volume to [{INT:Volume}]
This would continuously set the volume level while the key is held down (I.E. repeatedly, every ~200ms)
If you find that pauses are necessary, there should be no need to use variable pause actions over regular pause actions.
The "Level" field can take an integer variable name directly, so there's no need for the "{INT:}" token.

E.G.
Code: [Select]
Set integer [~previousVolume] value to the converted value of {STATE_SYSVOL}
Set system audio volume to [1]
Start Loop While :  Keyboard Key 'F22' Is Pressed
End Loop
Pause 0.1 seconds
Set system audio volume to [~previousVolume]

iceblast

  • Sr. Member
  • ****
  • Posts: 374
Re: Save the current speaker volume, and then set it's volume back?
« Reply #4 on: June 13, 2024, 11:54:03 PM »
Hmm, it's a pretty old command I made, there might have had been a reason for the pauses when I created it, but they don't appear to be needed anymore.