Audio alarm: Difference between revisions

Added Sidef
(Added Sidef)
 
(8 intermediate revisions by 6 users not shown)
Line 4:
=={{header|AutoHotkey}}==
Uses Run for maximum compatibility
<langsyntaxhighlight AHKlang="ahk">Inputbox, seconds, Seconds, Enter a number of seconds:
FileSelectFile, File, 3, %A_ScriptDir%, File to be played, MP3 Files (*.mp3)
Sleep Seconds*1000
RunWait % file</langsyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f AUDIOALARM.AWK
BEGIN {
Line 32:
exit(0)
}
</syntaxhighlight>
</lang>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">
@echo off
 
Line 52:
timeout /t %time% /nobreak >nul
start "" "%alarm%.mp3"
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 62:
{{libheader| Bass}}
'''Bass''' is a third part library, free for non-commercial use, can be found here [https://www.un4seen.com]. Require a '''bass.dll''' in the same folder of executable.
<syntaxhighlight lang="delphi">
<lang Delphi>
program AudioAlarm;
 
Line 159:
BASS_StreamFree(Music);
BASS_Free();
end.</langsyntaxhighlight>
{{out}}
<pre>Enter name of .mp3 file to play (without extension) :
Line 177:
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang="scheme">
(lib 'timer)
(lib 'audio)
Line 200:
Time to wake-up ;; + ... 🎼 🎶🎵🎶🎵
 
</syntaxhighlight>
</lang>
 
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">Dim As Long sec
Dim As String song
Input "Delay in seconds: ", sec
Input "MP3 to play as alarm: ", song
song &= ".mp3"
 
Sleep sec, 1
 
Dim As String exename = "wmplayer.exe"
Exec(exename, song)
 
Sleep</syntaxhighlight>
 
=={{header|FutureBasic}}==
FB has several audio/video play options from simple to professional. This demo code uses the simplest.
<syntaxhighlight lang="futurebasic">
 
include resources "Here Comes the Sun.mp3"
 
_window = 1
begin enum 1
_timerLabel
_timerField
_songLabel
_songField
_line
_timerBtn
end enum
 
begin globals
CFRunLoopTimerRef gTimer
NSInteger gCount
end globals
 
void local fn BuildWindow
NSUInteger i
CGRect r = fn CGRectMake( 0, 0, 400, 150 )
window _window, @"Audio Alarm", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + NSWindowStyleMaskMiniaturizable
r = fn CGRectMake( 5, 105, 195, 22 )
textlabel _timerLabel, @"Seconds until alarm:", r, _window
ControlSetAlignment( _timerLabel, NSTextAlignmentRight )
r = fn CGRectMake( 210, 108, 160, 22 )
textfield _timerField, YES, @"5", r, _window
ControlSetAlignment( _timerField, NSTextAlignmentLeft )
r = fn CGRectMake( 5, 72, 195, 24 )
textlabel _songLabel, @"Name of wake-up song:", r, _window
ControlSetAlignment( _songLabel, NSTextAlignmentRight )
r = fn CGRectMake( 210, 75, 160, 22 )
textfield _songField, YES, @"Here Comes the Sun", r, _window
ControlSetAlignment( _songField, NSTextAlignmentLeft )
r = fn CGRectMake( 30, 55, 340, 5 )
box _line,, r, NSBoxSeparator
for i = _timerLabel to _songField
ControlSetFontWithName( i, @"Menlo", 13.0 )
next
r = fn CGRectMake( 260, 13, 120, 32 )
button _timerBtn,,, @"Start timer", r, _window
end fn
 
local fn MyTimerCallback( t as CFRunLoopTimerRef )
window output _window
ControlSetIntegerValue( _timerField, gCount )
if ( gCount == 0 and gTimer != NULL )
TimerInvalidate( gTimer )
SoundRef alarmSound = fn SoundNamed( @"Here Comes the Sun" )
fn SoundPlay( alarmSound )
else
gCount--
end if
end fn
 
local fn StartTimer
gTimer = fn TimerScheduledWithInterval( 1, @fn MyTimerCallback, NULL, YES )
end fn
 
void local fn DoDialog( ev as long, tag as long, wnd as long )
select ( ev )
case _btnClick
select ( tag )
case _timerBtn : gCount = fn ControlIntegerValue( _timerField ) : fn StartTimer
end select
case _soundDidFinishPlaying : gCount = 5 : ControlSetIntegerValue( _timerField, gCount )
case _windowWillClose : end
end select
end fn
 
on dialog fn DoDialog
 
fn BuildWindow
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Audio Alarm.png]]
 
 
=={{header|Go}}==
As Go does not have any audio support in its standard library, this invokes the SoX utility's 'play' command to play the required .mp3 file.
<langsyntaxhighlight lang="go">package main
 
import (
Line 247 ⟶ 353:
log.Fatal(err)
}
}</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight Javalang="java">import com.sun.javafx.application.PlatformImpl;
import java.io.File;
import java.util.Scanner;
Line 288 ⟶ 394:
System.exit(0); // To stop the JavaFX thread.
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}/{{header|HTML}}==
<langsyntaxhighlight JavaScriptlang="javascript"><title> AudioAlarm </title>
<script>
var a=prompt("Enter a number of seconds", "");
var b=prompt("Enter the name of an MP3 file you have installed in the directory (without extension)", "");
document.write("<meta http-equiv='refresh' content='"+a+";url="+b+".mp3'>")
</script></langsyntaxhighlight>
 
=={{header|Julia}}==
Works when the computer will play an MP3 file with the "play" command.
<langsyntaxhighlight lang="julia">print("Enter seconds to wait: ")
(secs = tryparse(Int, readline())) == nothing && (secs = 10)
 
Line 311 ⟶ 417:
sleep(secs)
run(`play "$soundfile"`)
</syntaxhighlight>
</lang>
 
 
=={{header|Kotlin}}==
For this to work on Ubuntu, 'glib' and 'libav-tools' need to be installed on your system.
<langsyntaxhighlight lang="scala">// version 1.1.51
 
import javafx.application.Application
Line 363 ⟶ 469:
val fileName = readLine()!! + ".mp3"
AudioAlarm.create(seconds, fileName)
}</langsyntaxhighlight>
 
Sample input:
Line 375 ⟶ 481:
If not already running, this will add an extra delay...
It will error if the mp3 file does not exist in the specified path.
<langsyntaxhighlight lang="lb">nomainwin
 
prompt "Delay in seconds"; sec$
Line 388 ⟶ 494:
run "C:\Program Files\Windows Media Player\wmplayer.exe " +chr$(34) +f$ +chr$(34)
 
end</langsyntaxhighlight>
 
=={{header|Lua}}==
Line 394 ⟶ 500:
luasdl2 and luafilesystem libraries required.
 
<langsyntaxhighlight lang="lua">SDL = require "SDL"
mixer = require "SDL.mixer"
lfs = require "lfs"
Line 409 ⟶ 515:
print("Press Enter to quit")
io.read()
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
{{Trans|Go}}
<langsyntaxhighlight Nimlang="nim">import os, strutils, terminal
 
var delay: int
Line 444 ⟶ 550:
stdout.eraseScreen()
if execShellCmd("play $#.mp3" % filename) != 0:
echo "Error while playing mp3 file."</langsyntaxhighlight>
 
=={{header|OCaml}}==
requires mpg123 to be installed.
 
<langsyntaxhighlight lang="ocaml">let rec wait n = match n with
| 0 -> ()
| n -> Sys.command "sleep 1"; wait (n - 1);;
Line 461 ⟶ 567:
wait time;;
Sys.command ("mpg123 " ^ fileName);;
</syntaxhighlight>
</lang>
 
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(notonline)-->
<lang Phix>-- edit this as necessary!!
<span style="color: #000080;font-style:italic;">--
constant dflt = `C:\Program Files (x86)\Phix\demo\libxlsxwriter\euAllegro\Projects\RobotsR\Scream01.mp3`
-- demo\rosetta\AudioAlarm.exw
integer seconds = prompt_number("Enter a number of seconds: ")
-- ===========================
string mp3file = prompt_string("Enter an mp3 filename: ")
--
if mp3file="" then mp3file=dflt end if
-- If duration is checked then eg 1:30 means "perform a 90s countdown",
if not file_exists(mp3file) then crash("not found") end if
-- when unchecked the input is treated as a time of day, so 1:30 means
sleep(seconds)
-- "at half past one" (am, but you can enter pm, or 13:30), although a
include syswait.ew
-- "4" is bluntly ignored until you make it (say) "4pm" or "4:15". You
{} = system_open(mp3file)</lang>
-- should always [un]check //before// entering anything, btw.
--</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">dl</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`Download rosetta\bass\ from http://phix.x10.mx/pmwiki/pmwiki.php?n=Main.Bass`</span>
<span style="color: #7060A8;">assert</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_file_type</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"bass"</span><span style="color: #0000FF;">)=</span><span style="color: #004600;">FILETYPE_DIRECTORY</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dl</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">bass</span><span style="color: #0000FF;">\</span><span style="color: #000000;">bass</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #000000;">BASS_Init</span><span style="color: #0000FF;">(-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">44100</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">filePlayerHandle</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">BASS_StreamCreateFile</span><span style="color: #0000FF;">(</span><span style="color: #004600;">false</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`bass\Scream01.mp3`</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">mainwin</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">clock</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">alarm</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">durat</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">vbox1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">timer</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">secfmts</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"%d:%d:%d"</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- h:m:s</span>
<span style="color: #008000;">"%d:%d"</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- m:s</span>
<span style="color: #008000;">"%d"</span><span style="color: #0000FF;">},</span> <span style="color: #000080;font-style:italic;">-- s</span>
<span style="color: #000000;">pdsfmts</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"hh:mm:ss pm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh:mm:sspm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh:mm pm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh:mmpm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh pm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hhpm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh:mm:ss"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh:mm"</span><span style="color: #0000FF;">}</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">remain</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span> <span style="color: #000080;font-style:italic;">-- whole seconds (for both duration and at time),
-- with 0 meaning inactive/already triggered.</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">alarm_changed_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*alarm*/</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">txt</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">alarm</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">durat</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #000080;font-style:italic;">-- duration in [[h:]m:]s format, eg 1:30 means perform a 90s countdown</span>
<span style="color: #000000;">remain</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">f</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">secfmts</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">scanf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">txt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">secfmts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">f</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">remain</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">remain</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">+</span><span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">exit</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">else</span>
<span style="color: #000080;font-style:italic;">-- time of day in hh[:mm[:ss]][[ ]pm] format, eg 1:30 means "at half past one"</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">parse_date_string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">txt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pdsfmts</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">3</span> <span style="color: #008080;">then</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">today</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">date</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #004600;">DT_YEAR</span><span style="color: #0000FF;">..</span><span style="color: #004600;">DT_DAY</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">today</span><span style="color: #0000FF;">[</span><span style="color: #004600;">DT_YEAR</span><span style="color: #0000FF;">..</span><span style="color: #004600;">DT_DAY</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">remain</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">ceil</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">timedate_diff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">today</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">remain</span><span style="color: #0000FF;"><</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000000;">remain</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">get_now</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">date</span><span style="color: #0000FF;">(),</span><span style="color: #008000;">"hh:mm:sspm Dddd dth Mmmm yyyy"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">timer_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*timer*/</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetStrAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">clock</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">get_now</span><span style="color: #0000FF;">())</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">remain</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">remain</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">remain</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">hours</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">remain</span><span style="color: #0000FF;">/(</span><span style="color: #000000;">60</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">)),</span>
<span style="color: #000000;">seconds</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">remain</span><span style="color: #0000FF;">,</span><span style="color: #000000;">60</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">minutes</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">seconds</span><span style="color: #0000FF;">/</span><span style="color: #000000;">60</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">seconds</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">seconds</span><span style="color: #0000FF;">,</span><span style="color: #000000;">60</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetStrAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%02d:%02d:%02d"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">hours</span><span style="color: #0000FF;">,</span><span style="color: #000000;">minutes</span><span style="color: #0000FF;">,</span><span style="color: #000000;">seconds</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">else</span>
<span style="color: #7060A8;">IupSetStrAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">BASS_ChannelPlay</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filePlayerHandle</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_IGNORE</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">clock</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #000000;">get_now</span><span style="color: #0000FF;">(),</span><span style="color: #008000;">"EXPAND=HORIZONTAL"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"EXPAND=HORIZONTAL"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">alarm</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupText</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"VALUECHANGED_CB"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"alarm_changed_cb"</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">durat</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupToggle</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"duration"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE=ON, RIGHTBUTTON=YES"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">vbox1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupVbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Time:"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">clock</span><span style="color: #0000FF;">}),</span>
<span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">" Left:"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">count</span><span style="color: #0000FF;">}),</span>
<span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Alarm:"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">alarm</span><span style="color: #0000FF;">,</span><span style="color: #000000;">durat</span><span style="color: #0000FF;">},</span>
<span style="color: #008000;">"NORMALIZESIZE=VERTICAL"</span><span style="color: #0000FF;">)},</span>
<span style="color: #008000;">"NMARGIN=10x10,GAP=5"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">mainwin</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">vbox1</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`TITLE="Audio Alarm", RASTERSIZE=320x125`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mainwin</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">timer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupTimer</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"timer_cb"</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">1000</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
 
=={{header|Pure Data}}==
Line 592 ⟶ 793:
{{works with|Python|3.4.1}}
 
<langsyntaxhighlight lang="python">import time
import os
 
Line 599 ⟶ 800:
 
time.sleep(float(seconds))
os.startfile(sound + ".mp3")</langsyntaxhighlight>
 
=={{header|Racket}}==
Racket does not currently have native mp3 support so this example uses system to call an external application.
<langsyntaxhighlight lang="racket">#lang racket
(display "Time to wait in seconds: ")
(define time (string->number (read-line)))
Line 612 ⟶ 813:
(when (file-exists? (string->path (string-append file-name ".mp3")))
(sleep time)
(system* "/usr/bin/mpg123" (string-append file-name ".mp3")))</langsyntaxhighlight>
 
=={{header|Raku}}==
requires mpg123 to be installed.
<syntaxhighlight lang="raku" line># 20221111 Raku programming solution
 
loop (my $wait; $wait !~~ Int;) { $wait=prompt('enter seconds to wait: ') }
 
loop (my $mp3='';!"$mp3.mp3".IO.e;) { $mp3=prompt('enter filename to play: ') }
 
run '/usr/bin/clear';
 
sleep($wait);
 
run '/usr/bin/mpg123', "$mp3.mp3";</syntaxhighlight>
 
=={{header|REXX}}==
===using SLEEP===
<langsyntaxhighlight lang="rexx">/*REXX pgm to prompt user for: # (of secs); a name of a MP3 file to play*/
 
say '──────── Please enter a number of seconds to wait:'
Line 628 ⟶ 843:
call sleep waitTime
MP3FILE'.MP3'
/*stick a fork in it, we're done.*/</langsyntaxhighlight>
'''output''' when using the input of: <tt> xxx </tt>
 
===using spin===
<langsyntaxhighlight lang="rexx">/*REXX pgm to prompt user for: # (of secs); a name of a MP3 file to play*/
 
say '──────── Please enter a number of seconds to wait:'
Line 646 ⟶ 861:
 
MP3FILE'.MP3'
/*stick a fork in it, we're done.*/</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : AudioAlarm
 
Line 660 ⟶ 875:
sleep(sec)
system("C:\Ring\wmplayer.exe C:\Ring\calmosoft\" + f)
</syntaxhighlight>
</lang>
Output:
 
Line 668 ⟶ 883:
requires mpg123 to be installed.
 
<langsyntaxhighlight lang="ruby">puts "Enter a number of seconds:"
seconds = gets.chomp.to_i
puts "Enter a MP3 file to be played"
Line 674 ⟶ 889:
sleep(seconds)
pid = fork{ exec 'mpg123','-q', mp3filepath }
</syntaxhighlight>
</lang>
 
=={{header|Sidef}}==
Requires mpg123 to be installed.
<syntaxhighlight lang="ruby">var seconds = Sys.read("Enter a number of seconds: ", Number)
var mp3filepath = Sys.read("Enter a MP3 file to be played: ", File)+".mp3"
Sys.sleep(seconds)
Sys.run('mpg123', '-q', mp3filepath)</syntaxhighlight>
 
=={{header|Tcl}}==
{{libheader|Snack}}
<langsyntaxhighlight lang="tcl">package require sound
 
fconfigure stdout -buffering none
Line 694 ⟶ 916:
snd destroy
puts "all done"
exit</langsyntaxhighlight>
 
=={{header|Wren}}==
{{libheader|DOME}}
The number of seconds to wait and the alarm filename are passed as command line arguments rather than being requested individually.
 
Currently, DOME can only playback .wav and .ogg files so we use the former here.
<syntaxhighlight lang="wren">import "dome" for Window, Process, Platform
import "graphics" for Canvas, Color
import "audio" for AudioEngine
 
var StartTime = Platform.time
 
class AudioAlarm {
construct new() {
Window.title = "Audio alarm"
}
 
init() {
var args = Process.args
if (args.count != 4) {
System.print("Two arguments should be passed at the command line, viz:")
System.print(" dome audio_alarm.wren <seconds to wait> <wav filename without extension>")
System.print("Exiting DOME")
Process.exit()
}
_secs = Num.fromString(args[2])
_wav = args[3] + ".wav"
Canvas.print("Alarm will sound in %(_secs) seconds...", 10, 10, Color.white)
AudioEngine.load("alarm", _wav)
_alarmed = true
}
 
update() {
var currTime = Platform.time
if (_alarmed && (currTime >= StartTime + _secs)) {
AudioEngine.play("alarm")
_alarmed = false
Canvas.cls()
Canvas.print("Alarm has sounded", 10, 10, Color.white)
}
}
 
draw(alpha) {}
}
 
var Game = AudioAlarm.new()</syntaxhighlight>
 
=={{header|XPL0}}==
Works on Raspberry Pi.
<langsyntaxhighlight XPL0lang="xpl0">int Time, I, J, Ch;
char FN(80), Ext;
[Text(0, "Number of seconds to wait? ");
Line 715 ⟶ 983:
DelayUs(Time * 1_000_000);
PlaySoundFile(FN);
]</langsyntaxhighlight>
 
=={{header|Yabasic}}==
<langsyntaxhighlight Yabasiclang="yabasic">input "How long to wait for (seconds): " sec
input "What file to play: " song$
wait sec
Line 724 ⟶ 992:
 
system("explorer " + song$)
exit 0</langsyntaxhighlight>
 
=={{header|zkl}}==
There is no built in sound support so this example is coded for my Linux box.
A change: rather than seconds to wait, a time is used.
<langsyntaxhighlight lang="zkl">hms :=Time.Date.parseTime(ask("Time to play mp3 file: "));
file:=ask("File to play: ") + ".mp3";
 
Line 742 ⟶ 1,010:
//Atomic.sleep(time);
//System.cmd("mplayer "+file);
</syntaxhighlight>
</lang>
{{out}}
<pre>
2,747

edits