Audio alarm: Difference between revisions

Content added Content deleted
(→‎{{header|Phix}}: replaced with gui version)
m (syntax highlighting fixup automation)
Line 4: Line 4:
=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
Uses Run for maximum compatibility
Uses Run for maximum compatibility
<lang AHK>Inputbox, seconds, Seconds, Enter a number of seconds:
<syntaxhighlight lang=AHK>Inputbox, seconds, Seconds, Enter a number of seconds:
FileSelectFile, File, 3, %A_ScriptDir%, File to be played, MP3 Files (*.mp3)
FileSelectFile, File, 3, %A_ScriptDir%, File to be played, MP3 Files (*.mp3)
Sleep Seconds*1000
Sleep Seconds*1000
RunWait % file</lang>
RunWait % file</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<lang AWK>
<syntaxhighlight lang=AWK>
# syntax: GAWK -f AUDIOALARM.AWK
# syntax: GAWK -f AUDIOALARM.AWK
BEGIN {
BEGIN {
Line 32: Line 32:
exit(0)
exit(0)
}
}
</syntaxhighlight>
</lang>


=={{header|Batch File}}==
=={{header|Batch File}}==
<lang dos>
<syntaxhighlight lang=dos>
@echo off
@echo off


Line 52: Line 52:
timeout /t %time% /nobreak >nul
timeout /t %time% /nobreak >nul
start "" "%alarm%.mp3"
start "" "%alarm%.mp3"
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 62: Line 62:
{{libheader| Bass}}
{{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.
'''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.
<lang Delphi>
<syntaxhighlight lang=Delphi>
program AudioAlarm;
program AudioAlarm;


Line 159: Line 159:
BASS_StreamFree(Music);
BASS_StreamFree(Music);
BASS_Free();
BASS_Free();
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>Enter name of .mp3 file to play (without extension) :
<pre>Enter name of .mp3 file to play (without extension) :
Line 177: Line 177:


=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
<lang scheme>
<syntaxhighlight lang=scheme>
(lib 'timer)
(lib 'timer)
(lib 'audio)
(lib 'audio)
Line 200: Line 200:
Time to wake-up ;; + ... 🎼 🎶🎵🎶🎵
Time to wake-up ;; + ... 🎼 🎶🎵🎶🎵


</syntaxhighlight>
</lang>




=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>Dim As Long sec
<syntaxhighlight lang=freebasic>Dim As Long sec
Dim As String song
Dim As String song
Input "Delay in seconds: ", sec
Input "Delay in seconds: ", sec
Line 215: Line 215:
Exec(exename, song)
Exec(exename, song)


Sleep</lang>
Sleep</syntaxhighlight>




=={{header|Go}}==
=={{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.
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.
<lang go>package main
<syntaxhighlight lang=go>package main


import (
import (
Line 263: Line 263:
log.Fatal(err)
log.Fatal(err)
}
}
}</lang>
}</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
<lang Java>import com.sun.javafx.application.PlatformImpl;
<syntaxhighlight lang=Java>import com.sun.javafx.application.PlatformImpl;
import java.io.File;
import java.io.File;
import java.util.Scanner;
import java.util.Scanner;
Line 304: Line 304:
System.exit(0); // To stop the JavaFX thread.
System.exit(0); // To stop the JavaFX thread.
}
}
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}/{{header|HTML}}==
=={{header|JavaScript}}/{{header|HTML}}==
<lang JavaScript><title> AudioAlarm </title>
<syntaxhighlight lang=JavaScript><title> AudioAlarm </title>
<script>
<script>
var a=prompt("Enter a number of seconds", "");
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)", "");
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'>")
document.write("<meta http-equiv='refresh' content='"+a+";url="+b+".mp3'>")
</script></lang>
</script></syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
Works when the computer will play an MP3 file with the "play" command.
Works when the computer will play an MP3 file with the "play" command.
<lang julia>print("Enter seconds to wait: ")
<syntaxhighlight lang=julia>print("Enter seconds to wait: ")
(secs = tryparse(Int, readline())) == nothing && (secs = 10)
(secs = tryparse(Int, readline())) == nothing && (secs = 10)


Line 327: Line 327:
sleep(secs)
sleep(secs)
run(`play "$soundfile"`)
run(`play "$soundfile"`)
</syntaxhighlight>
</lang>




=={{header|Kotlin}}==
=={{header|Kotlin}}==
For this to work on Ubuntu, 'glib' and 'libav-tools' need to be installed on your system.
For this to work on Ubuntu, 'glib' and 'libav-tools' need to be installed on your system.
<lang scala>// version 1.1.51
<syntaxhighlight lang=scala>// version 1.1.51


import javafx.application.Application
import javafx.application.Application
Line 379: Line 379:
val fileName = readLine()!! + ".mp3"
val fileName = readLine()!! + ".mp3"
AudioAlarm.create(seconds, fileName)
AudioAlarm.create(seconds, fileName)
}</lang>
}</syntaxhighlight>


Sample input:
Sample input:
Line 391: Line 391:
If not already running, this will add an extra delay...
If not already running, this will add an extra delay...
It will error if the mp3 file does not exist in the specified path.
It will error if the mp3 file does not exist in the specified path.
<lang lb>nomainwin
<syntaxhighlight lang=lb>nomainwin


prompt "Delay in seconds"; sec$
prompt "Delay in seconds"; sec$
Line 404: Line 404:
run "C:\Program Files\Windows Media Player\wmplayer.exe " +chr$(34) +f$ +chr$(34)
run "C:\Program Files\Windows Media Player\wmplayer.exe " +chr$(34) +f$ +chr$(34)


end</lang>
end</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
Line 410: Line 410:
luasdl2 and luafilesystem libraries required.
luasdl2 and luafilesystem libraries required.


<lang lua>SDL = require "SDL"
<syntaxhighlight lang=lua>SDL = require "SDL"
mixer = require "SDL.mixer"
mixer = require "SDL.mixer"
lfs = require "lfs"
lfs = require "lfs"
Line 425: Line 425:
print("Press Enter to quit")
print("Press Enter to quit")
io.read()
io.read()
</syntaxhighlight>
</lang>


=={{header|Nim}}==
=={{header|Nim}}==
{{Trans|Go}}
{{Trans|Go}}
<lang Nim>import os, strutils, terminal
<syntaxhighlight lang=Nim>import os, strutils, terminal


var delay: int
var delay: int
Line 460: Line 460:
stdout.eraseScreen()
stdout.eraseScreen()
if execShellCmd("play $#.mp3" % filename) != 0:
if execShellCmd("play $#.mp3" % filename) != 0:
echo "Error while playing mp3 file."</lang>
echo "Error while playing mp3 file."</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
requires mpg123 to be installed.
requires mpg123 to be installed.


<lang ocaml>let rec wait n = match n with
<syntaxhighlight lang=ocaml>let rec wait n = match n with
| 0 -> ()
| 0 -> ()
| n -> Sys.command "sleep 1"; wait (n - 1);;
| n -> Sys.command "sleep 1"; wait (n - 1);;
Line 477: Line 477:
wait time;;
wait time;;
Sys.command ("mpg123 " ^ fileName);;
Sys.command ("mpg123 " ^ fileName);;
</syntaxhighlight>
</lang>




=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(notonline)-->
<!--<syntaxhighlight lang=Phix>(notonline)-->
<span style="color: #000080;font-style:italic;">--
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\AudioAlarm.exw
-- demo\rosetta\AudioAlarm.exw
Line 584: Line 584:
<span style="color: #7060A8;">IupMainLoop</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>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|Pure Data}}==
=={{header|Pure Data}}==
Line 703: Line 703:
{{works with|Python|3.4.1}}
{{works with|Python|3.4.1}}


<lang python>import time
<syntaxhighlight lang=python>import time
import os
import os


Line 710: Line 710:


time.sleep(float(seconds))
time.sleep(float(seconds))
os.startfile(sound + ".mp3")</lang>
os.startfile(sound + ".mp3")</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Racket does not currently have native mp3 support so this example uses system to call an external application.
Racket does not currently have native mp3 support so this example uses system to call an external application.
<lang racket>#lang racket
<syntaxhighlight lang=racket>#lang racket
(display "Time to wait in seconds: ")
(display "Time to wait in seconds: ")
(define time (string->number (read-line)))
(define time (string->number (read-line)))
Line 723: Line 723:
(when (file-exists? (string->path (string-append file-name ".mp3")))
(when (file-exists? (string->path (string-append file-name ".mp3")))
(sleep time)
(sleep time)
(system* "/usr/bin/mpg123" (string-append file-name ".mp3")))</lang>
(system* "/usr/bin/mpg123" (string-append file-name ".mp3")))</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
===using SLEEP===
===using SLEEP===
<lang rexx>/*REXX pgm to prompt user for: # (of secs); a name of a MP3 file to play*/
<syntaxhighlight 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:'
say '──────── Please enter a number of seconds to wait:'
Line 739: Line 739:
call sleep waitTime
call sleep waitTime
MP3FILE'.MP3'
MP3FILE'.MP3'
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</syntaxhighlight>
'''output''' when using the input of: <tt> xxx </tt>
'''output''' when using the input of: <tt> xxx </tt>


===using spin===
===using spin===
<lang rexx>/*REXX pgm to prompt user for: # (of secs); a name of a MP3 file to play*/
<syntaxhighlight 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:'
say '──────── Please enter a number of seconds to wait:'
Line 757: Line 757:


MP3FILE'.MP3'
MP3FILE'.MP3'
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</syntaxhighlight>


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang=ring>
# Project : AudioAlarm
# Project : AudioAlarm


Line 771: Line 771:
sleep(sec)
sleep(sec)
system("C:\Ring\wmplayer.exe C:\Ring\calmosoft\" + f)
system("C:\Ring\wmplayer.exe C:\Ring\calmosoft\" + f)
</syntaxhighlight>
</lang>
Output:
Output:


Line 779: Line 779:
requires mpg123 to be installed.
requires mpg123 to be installed.


<lang ruby>puts "Enter a number of seconds:"
<syntaxhighlight lang=ruby>puts "Enter a number of seconds:"
seconds = gets.chomp.to_i
seconds = gets.chomp.to_i
puts "Enter a MP3 file to be played"
puts "Enter a MP3 file to be played"
Line 785: Line 785:
sleep(seconds)
sleep(seconds)
pid = fork{ exec 'mpg123','-q', mp3filepath }
pid = fork{ exec 'mpg123','-q', mp3filepath }
</syntaxhighlight>
</lang>


=={{header|Tcl}}==
=={{header|Tcl}}==
{{libheader|Snack}}
{{libheader|Snack}}
<lang tcl>package require sound
<syntaxhighlight lang=tcl>package require sound


fconfigure stdout -buffering none
fconfigure stdout -buffering none
Line 805: Line 805:
snd destroy
snd destroy
puts "all done"
puts "all done"
exit</lang>
exit</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
Line 812: Line 812:


Currently, DOME can only playback .wav and .ogg files so we use the former here.
Currently, DOME can only playback .wav and .ogg files so we use the former here.
<lang ecmascript>import "dome" for Window, Process, Platform
<syntaxhighlight lang=ecmascript>import "dome" for Window, Process, Platform
import "graphics" for Canvas, Color
import "graphics" for Canvas, Color
import "audio" for AudioEngine
import "audio" for AudioEngine
Line 851: Line 851:
}
}


var Game = AudioAlarm.new()</lang>
var Game = AudioAlarm.new()</syntaxhighlight>


=={{header|XPL0}}==
=={{header|XPL0}}==
Works on Raspberry Pi.
Works on Raspberry Pi.
<lang XPL0>int Time, I, J, Ch;
<syntaxhighlight lang=XPL0>int Time, I, J, Ch;
char FN(80), Ext;
char FN(80), Ext;
[Text(0, "Number of seconds to wait? ");
[Text(0, "Number of seconds to wait? ");
Line 872: Line 872:
DelayUs(Time * 1_000_000);
DelayUs(Time * 1_000_000);
PlaySoundFile(FN);
PlaySoundFile(FN);
]</lang>
]</syntaxhighlight>


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<lang Yabasic>input "How long to wait for (seconds): " sec
<syntaxhighlight lang=Yabasic>input "How long to wait for (seconds): " sec
input "What file to play: " song$
input "What file to play: " song$
wait sec
wait sec
Line 881: Line 881:


system("explorer " + song$)
system("explorer " + song$)
exit 0</lang>
exit 0</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
There is no built in sound support so this example is coded for my Linux box.
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.
A change: rather than seconds to wait, a time is used.
<lang zkl>hms :=Time.Date.parseTime(ask("Time to play mp3 file: "));
<syntaxhighlight lang=zkl>hms :=Time.Date.parseTime(ask("Time to play mp3 file: "));
file:=ask("File to play: ") + ".mp3";
file:=ask("File to play: ") + ".mp3";


Line 899: Line 899:
//Atomic.sleep(time);
//Atomic.sleep(time);
//System.cmd("mplayer "+file);
//System.cmd("mplayer "+file);
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>