Play a sound every 00 and 30 minute marks

Post your working scripts, libraries and tools
User avatar
joshebosh
Posts: 5
Joined: 23 May 2016, 19:15

Play a sound every 00 and 30 minute marks

13 Aug 2018, 08:44

I wasnt happy with other scripts I found out there, so i figured i'd post my own...

I orginally went with playing a sound every 15 minutes, but I commented out those lines and went with every 30 minutes, on the top and bottom of hour. You can set the hours of operation, and set quarter hour marks if you uncommen/comment tick2 and tick4 (and swap the IF and WHILE lines). The while line is to sleep during the 00 and 30 ticks so you only hear the sound play one time during that 60 second window.

Code: Select all

#SingleInstance, Force

open := 0800
close := 1900
tick1 := 00
;tick2 := 15
tick3 := 30
;tick4 := 45

Loop {
	ticker := A_Min
	current_time := A_Hour . A_Min
;	If (((current_time > open) and (current_time < close)) and ((ticker = tick1) or (ticker = tick2) or (ticker = tick3) or (ticker = tick4)))
	If (((current_time > open) and (current_time < close)) and ((ticker = tick1) or (ticker = tick3)))
	{
		SoundPlay, F:\Google Drive\Audio\misc audio\Ringtones\Attention.mp3
		;While ((ticker = tick1) or (ticker = tick2) or (ticker = tick3) or (ticker = tick4))
		While ((ticker = tick1) or (ticker = tick3))
		{
			Sleep, 2000
			ticker := A_Min
		}
	}
	Else
		Sleep, 2000
}

^F9::ExitApp
User avatar
Grendahl
Posts: 159
Joined: 30 Sep 2013, 08:21

Re: Play a sound every 00 and 30 minute marks

13 Aug 2018, 12:25

You could also do something like this:

Code: Select all

;
; TimeSpeak v1.1
;	by Grendahl
;	Announces the time on the hour using Microsoft's text-to-speech engine
;
; Change Log
; 	v1.1 (2011-11-28)
; 	First version (inspired by http://www.autohotkey.com/forum/viewtopic.php?t=14305)


;********** settings, variable declarations **********
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance Force


;********** auto-execute section **********
SetTimer, AnnounceHour, 1000
Return


;********** hotkeys **********
!ESC::ExitApp
!t::gosub SayTime


;********** subroutines **********
AnnounceHour:
	FormatTime, AnnounceHour, %A_Now%, h ; get current hour
	FormatTime, AnnounceMinute, %A_Now%, m ; get current minutes
	FormatTime, AnnounceAMPM, %A_Now%, tt ; get AM/PM

	If(AnnounceMinute<1)
	{
		IfInString, AnnounceAMPM, AM ; If AM, say a m instead of ameters
			AnnounceAMPM = ae em
		IfInString, AnnounceAMPM, PM ; If PM, say p m instead of pmeters
			AnnounceAMPM = pee em

		AnnounceHourString = The time is %AnnounceHour% %AnnounceAMPM% ;oh clock %AnnounceAMPM% ; announce time
		ComObjCreate("SAPI.SpVoice").Speak(AnnounceHourString)
		
		sleep 1000
		loop %AnnounceHour%
		{
			SoundPlay, %A_ScriptDir%\Chime.wav
			Sleep 1200
		}
	}
	
	If(AnnounceMinute=15 || AnnounceMinute=30 || AnnounceMinute=45)
	{
		IfInString, AnnounceAMPM, AM ; If AM, say a m instead of ameters
			AnnounceAMPM = ae em
		IfInString, AnnounceAMPM, PM ; If PM, say p m instead of pmeters
			AnnounceAMPM = pee em

		AnnounceHourString = The time is %AnnounceHour%  %AnnounceMinute%  %AnnounceAMPM% ;oh clock %AnnounceAMPM% ; announce time
		ComObjCreate("SAPI.SpVoice").Speak(AnnounceHourString)
	}
	
	SetTimer, AnnounceHour, Off ; stop the timer for 90 seconds so we don't get spammed
	Sleep 90000
	SetTimer, AnnounceHour, On
	
Return

SayTime:
	FormatTime, SayHour, %A_Now%, h ; get current hour
	FormatTime, SayMinute, %A_Now%, m ; get current minutes
	FormatTime, SayAMPM, %A_Now%, tt ; get AM/PM
	
	If(SayMinute>0 && SayMinute<10) ; add the "oh" for minutes 1 through nine
		SayMinute = oh %SayMinute%
	If(SayMinute=0) ; if the current minute is 0, say oh clock instead of zero
		SayMinute = oh clock
	IfInString, SayAMPM, AM ; If AM, say a m instead of ameters
		SayAMPM = ae em
	IfInString, SayAMPM, PM ; If PM, say p m instead of pmeters
		SayAMPM = pee em

	SayTimeString = The time is %SayHour% %SayMinute% %SayAMPM% ; announce time
	ComObjCreate("SAPI.SpVoice").Speak(SayTimeString)
Return
carno
Posts: 129
Joined: 20 Jun 2014, 16:48

Re: Play a sound every 00 and 30 minute marks

16 Sep 2018, 13:25

I have started testing Grendahl's TimeSpeak :) .

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 51 guests