SoundBeep volume

Get help with using AutoHotkey and its commands and hotkeys
totya
Posts: 11
Joined: 10 Jan 2016, 07:00

SoundBeep volume

28 Aug 2016, 12:20

Hi!

Can I use SoundBeep function, but with specificed volume?

Thanks!
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: SoundBeep volume

28 Aug 2016, 13:02

Try this:

Code: Select all

SoundBeep(440, 1000, 20)
SoundBeep(440, 1000, 40)
SoundBeep(440, 1000, 60)
SoundBeep(440, 1000, 80)
ExitApp



;-------------------------------------------------------------------------------
SoundBeep(Frequency, Duration, Volume) { ; custom wrapper
;-------------------------------------------------------------------------------
    SoundGet, MasterVolume
    SoundSet, Volume
    SoundBeep, Frequency, Duration
    SoundSet, MasterVolume
}
I hope that helps.
totya
Posts: 11
Joined: 10 Jan 2016, 07:00

Re: SoundBeep volume

28 Aug 2016, 13:54

Hi!

Thank you for this clean code, I wrote already similar of this, but I have a problem, if I use this code when my all scripts reload, sometimes MasterVolme is not preserve the original state.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: SoundBeep volume

28 Aug 2016, 16:08

totya wrote:I have a problem, if I use this code when my all scripts reload, sometimes MasterVolme is not preserve the original state.

Code: Select all

OnExit, restore_MasterVolume ; this tells the reload command what to do

SoundBeep(440, 1000, 20)
SoundBeep(440, 1000, 40)
SoundBeep(440, 1000, 60)
SoundBeep(440, 1000, 80)
ExitApp



;-------------------------------------------------------------------------------
SoundBeep(Frequency, Duration, Volume) { ; custom wrapper
;-------------------------------------------------------------------------------
    global MasterVolume ; use the same variable as "restore_MasterVolume"

    SoundGet, MasterVolume
    SoundSet, Volume
    SoundBeep, Frequency, Duration
    SoundSet, MasterVolume
}



;-------------------------------------------------------------------------------
restore_MasterVolume: ; called by the reload command
;-------------------------------------------------------------------------------
    SoundSet, MasterVolume

Return
I hope that helps.
SSpeed
Posts: 25
Joined: 04 Jul 2018, 09:48

Re: SoundBeep volume

26 Sep 2020, 15:14

Here is the simple: (with a chance of not returning your volume level)

Code: Select all

SoundBeep(700, 50)
sleep 150
exitapp

;-------------------------------------------------------------------------------

	soundbeep(frequency:=523, volume:=50) {
		soundget current_volume
		soundset % volume
		soundbeep % frequency
		sleep 150
		soundset current_volume
	}

;-------------------------------------------------------------------------------

*Esc:: Exitapp

and here is the one that should return your volume level, even when reloading or exiting:

Code: Select all

SoundBeep(700, 50)
sleep 150
exitapp

;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

	soundbeep(frequency:=523, volume:=50) {
		global master_volume, volume_unset
		static _ := onexit("on_exit_sb")
		if not (volume_unset) {
			soundget master_volume
			volume_unset := true
		} soundset % volume
		soundbeep % frequency
		settimer, return_master_volume, -150
	}
		return_master_volume() {
			global master_volume, volume_unset
			soundset master_volume
			volume_unset := false
		}
			on_exit_sb() {
				global master_volume, volume_unset
				if (volume_unset) {
					sleep 150
					SoundSet % master_volume
				}
			}

;▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

*Esc:: Exitapp

Use whatever you need.

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], mikeyww and 41 guests