Audio alarm: Difference between revisions
Added Sidef
(julia example) |
(Added Sidef) |
||
(13 intermediate revisions by 10 users not shown) | |||
Line 4:
=={{header|AutoHotkey}}==
Uses Run for maximum compatibility
<
FileSelectFile, File, 3, %A_ScriptDir%, File to be played, MP3 Files (*.mp3)
Sleep Seconds*1000
RunWait % file</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f AUDIOALARM.AWK
BEGIN {
Line 32:
exit(0)
}
</syntaxhighlight>
=={{header|Batch File}}==
<
@echo off
Line 52:
timeout /t %time% /nobreak >nul
start "" "%alarm%.mp3"
</syntaxhighlight>
{{out}}
<pre>
Line 58:
Input name of alarm: alarm name with spaces
</pre>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{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">
program AudioAlarm;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
Bass;
procedure Wait(sec: Cardinal; verbose: Boolean = False);
begin
while sec > 0 do
begin
if verbose then
Writeln(sec);
Sleep(1000); // 1s
dec(sec);
end;
end;
function QueryMp3File: string;
begin
while True do
begin
Writeln('Enter name of .mp3 file to play (without extension) : ');
Readln(Result);
Result := Result + '.mp3';
if not FileExists(Result) then
begin
Writeln('The file "' + Result + '" not exist');
Continue;
end;
Break;
end;
end;
function QueryIntNumber(): Integer;
var
val: string;
begin
Result := 0;
repeat
Writeln('Enter number of seconds delay > 0 : ');
Readln(val);
if not TryStrToInt(val, Result) then
begin
Writeln('"', val, '" is not a valid number.');
Continue;
end;
if Result <= 0 then
begin
Writeln('"', val, '" must be greater then 0');
Continue;
end;
until Result > 0;
end;
function CreateMusic(MusicName: string): HSTREAM;
var
buffer: PChar;
begin
buffer := pchar(MusicName);
// Initialize audio - default device, 44100hz, stereo, 16 bits
if not BASS_Init(-1, 44100, 0, 0, nil) then
Writeln('Error initializing audio!');
Result := BASS_StreamCreateFile(False, buffer, 0, 0, 0{$IFDEF UNICODE} or
BASS_UNICODE {$ENDIF});
if Result = 0 then
Writeln('Error on load music!');
end;
procedure Play(Music:HSTREAM);
begin
if not BASS_ChannelPlay(Music, True) then
Writeln('Error playing music!');
end;
var
Music: HSTREAM;
MusicName: string;
delay: Cardinal;
begin
MusicName := QueryMp3File;
delay := QueryIntNumber;
Music := CreateMusic(MusicName);
Wait(delay, True);
Play(Music);
Readln;
BASS_StreamFree(Music);
BASS_Free();
end.</syntaxhighlight>
{{out}}
<pre>Enter name of .mp3 file to play (without extension) :
AudioAlarm
Enter number of seconds delay > 0 :
10
10
9
8
7
6
5
4
3
2
1</pre>
=={{header|EchoLisp}}==
<
(lib 'timer)
(lib 'audio)
Line 83 ⟶ 200:
Time to wake-up ;; + ... 🎼 🎶🎵🎶🎵
</syntaxhighlight>
=={{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.
<
import (
Line 130 ⟶ 353:
log.Fatal(err)
}
}</
=={{header|Java}}==
<
import java.io.File;
import java.util.Scanner;
Line 171 ⟶ 394:
System.exit(0); // To stop the JavaFX thread.
}
}</
=={{header|JavaScript}}/{{header|HTML}}==
<
<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></
=={{header|Julia}}==
Works when the computer will play an MP3 file with the "play" command.
<
(secs = tryparse(Int, readline())) == nothing && (secs = 10)
Line 194 ⟶ 417:
sleep(secs)
run(`play "$soundfile"`)
</syntaxhighlight>
=={{header|Kotlin}}==
For this to work on Ubuntu, 'glib' and 'libav-tools' need to be installed on your system.
<
import javafx.application.Application
Line 246 ⟶ 469:
val fileName = readLine()!! + ".mp3"
AudioAlarm.create(seconds, fileName)
}</
Sample input:
Line 258 ⟶ 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.
<
prompt "Delay in seconds"; sec$
Line 271 ⟶ 494:
run "C:\Program Files\Windows Media Player\wmplayer.exe " +chr$(34) +f$ +chr$(34)
end</
=={{header|Lua}}==
Line 277 ⟶ 500:
luasdl2 and luafilesystem libraries required.
<
mixer = require "SDL.mixer"
lfs = require "lfs"
Line 292 ⟶ 515:
print("Press Enter to quit")
io.read()
</syntaxhighlight>
=={{header|Nim}}==
{{Trans|Go}}
<syntaxhighlight lang="nim">import os, strutils, terminal
var delay: int
while true:
stdout.write "Enter delay in seconds: "
stdout.flushFile()
try:
delay = stdin.readLine.strip().parseInt()
break
except ValueError:
echo "Error: invalid value."
except EOFError:
echo()
quit "Quitting.", QuitFailure
var filename: string
while true:
stdout.write "Enter mp3 file name (without extension): "
stdout.flushFile()
try:
filename = stdin.readLine
break
except EOFError:
echo ()
quit "Quitting.", QuitFailure
stdout.eraseScreen()
echo "Alarm will sound in $# second(s)...".format(delay)
os.sleep delay * 1000
stdout.eraseScreen()
if execShellCmd("play $#.mp3" % filename) != 0:
echo "Error while playing mp3 file."</syntaxhighlight>
=={{header|OCaml}}==
requires mpg123 to be installed.
<syntaxhighlight lang="ocaml">let rec wait n = match n with
| 0 -> ()
| n -> Sys.command "sleep 1"; wait (n - 1);;
Printf.printf "Please enter a number of seconds\n";;
let time = read_int ();;
Printf.printf "Please enter a file name\n";;
let fileName = (read_line ()) ^ ".mp3";;
wait time;;
Sys.command ("mpg123 " ^ fileName);;
</syntaxhighlight>
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\AudioAlarm.exw
-- ===========================
--
-- If duration is checked then eg 1:30 means "perform a 90s countdown",
-- when unchecked the input is treated as a time of day, so 1:30 means
-- "at half past one" (am, but you can enter pm, or 13:30), although a
-- "4" is bluntly ignored until you make it (say) "4pm" or "4:15". You
-- 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 422 ⟶ 793:
{{works with|Python|3.4.1}}
<
import os
Line 429 ⟶ 800:
time.sleep(float(seconds))
os.startfile(sound + ".mp3")</
=={{header|Racket}}==
Racket does not currently have native mp3 support so this example uses system to call an external application.
<
(display "Time to wait in seconds: ")
(define time (string->number (read-line)))
Line 442 ⟶ 813:
(when (file-exists? (string->path (string-append file-name ".mp3")))
(sleep time)
(system* "/usr/bin/mpg123" (string-append file-name ".mp3")))</
=={{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===
<
say '──────── Please enter a number of seconds to wait:'
Line 458 ⟶ 843:
call sleep waitTime
MP3FILE'.MP3'
/*stick a fork in it, we're done.*/</
'''output''' when using the input of: <tt> xxx </tt>
===using spin===
<
say '──────── Please enter a number of seconds to wait:'
Line 476 ⟶ 861:
MP3FILE'.MP3'
/*stick a fork in it, we're done.*/</
=={{header|Ring}}==
<
# Project : AudioAlarm
Line 490 ⟶ 875:
sleep(sec)
system("C:\Ring\wmplayer.exe C:\Ring\calmosoft\" + f)
</syntaxhighlight>
Output:
Line 498 ⟶ 883:
requires mpg123 to be installed.
<
seconds = gets.chomp.to_i
puts "Enter a MP3 file to be played"
Line 504 ⟶ 889:
sleep(seconds)
pid = fork{ exec 'mpg123','-q', mp3filepath }
</syntaxhighlight>
=={{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}}
<
fconfigure stdout -buffering none
Line 524 ⟶ 916:
snd destroy
puts "all done"
exit</
=={{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.
<syntaxhighlight lang="xpl0">int Time, I, J, Ch;
char FN(80), Ext;
[Text(0, "Number of seconds to wait? ");
Time:= IntIn(0);
Text(0, "Name of mp3 file to play? ");
I:= 0;
loop [Ch:= ChIn(0);
if Ch = \CR\$0D then quit;
FN(I):= Ch;
I:= I+1;
];
Ext:= ".mp3";
for J:= 0 to 3 do
FN(I+J):= Ext(J);
ChOut(0, $0C); \blank screen with form feed
DelayUs(Time * 1_000_000);
PlaySoundFile(FN);
]</syntaxhighlight>
=={{header|Yabasic}}==
<
input "What file to play: " song$
wait sec
Line 533 ⟶ 992:
system("explorer " + song$)
exit 0</
=={{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.
<
file:=ask("File to play: ") + ".mp3";
Line 551 ⟶ 1,010:
//Atomic.sleep(time);
//System.cmd("mplayer "+file);
</syntaxhighlight>
{{out}}
<pre>
|