Audio alarm: Difference between revisions

m
syntax highlighting fixup automation
(→‎{{header|Phix}}: replaced with gui version)
m (syntax highlighting fixup automation)
Line 4:
=={{header|AutoHotkey}}==
Uses Run for maximum compatibility
<langsyntaxhighlight lang=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}}==
<langsyntaxhighlight 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.
<langsyntaxhighlight 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}}==
<langsyntaxhighlight lang=freebasic>Dim As Long sec
Dim As String song
Input "Delay in seconds: ", sec
Line 215:
Exec(exename, song)
 
Sleep</langsyntaxhighlight>
 
 
=={{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 263:
log.Fatal(err)
}
}</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang=Java>import com.sun.javafx.application.PlatformImpl;
import java.io.File;
import java.util.Scanner;
Line 304:
System.exit(0); // To stop the JavaFX thread.
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}/{{header|HTML}}==
<langsyntaxhighlight lang=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 327:
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 379:
val fileName = readLine()!! + ".mp3"
AudioAlarm.create(seconds, fileName)
}</langsyntaxhighlight>
 
Sample input:
Line 391:
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 404:
run "C:\Program Files\Windows Media Player\wmplayer.exe " +chr$(34) +f$ +chr$(34)
 
end</langsyntaxhighlight>
 
=={{header|Lua}}==
Line 410:
luasdl2 and luafilesystem libraries required.
 
<langsyntaxhighlight lang=lua>SDL = require "SDL"
mixer = require "SDL.mixer"
lfs = require "lfs"
Line 425:
print("Press Enter to quit")
io.read()
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
{{Trans|Go}}
<langsyntaxhighlight lang=Nim>import os, strutils, terminal
 
var delay: int
Line 460:
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 477:
wait time;;
Sys.command ("mpg123 " ^ fileName);;
</syntaxhighlight>
</lang>
 
 
=={{header|Phix}}==
<!--<langsyntaxhighlight lang=Phix>(notonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\AudioAlarm.exw
Line 584:
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Pure Data}}==
Line 703:
{{works with|Python|3.4.1}}
 
<langsyntaxhighlight lang=python>import time
import os
 
Line 710:
 
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 723:
(when (file-exists? (string->path (string-append file-name ".mp3")))
(sleep time)
(system* "/usr/bin/mpg123" (string-append file-name ".mp3")))</langsyntaxhighlight>
 
=={{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 739:
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 757:
 
MP3FILE'.MP3'
/*stick a fork in it, we're done.*/</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang=ring>
# Project : AudioAlarm
 
Line 771:
sleep(sec)
system("C:\Ring\wmplayer.exe C:\Ring\calmosoft\" + f)
</syntaxhighlight>
</lang>
Output:
 
Line 779:
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 785:
sleep(seconds)
pid = fork{ exec 'mpg123','-q', mp3filepath }
</syntaxhighlight>
</lang>
 
=={{header|Tcl}}==
{{libheader|Snack}}
<langsyntaxhighlight lang=tcl>package require sound
 
fconfigure stdout -buffering none
Line 805:
snd destroy
puts "all done"
exit</langsyntaxhighlight>
 
=={{header|Wren}}==
Line 812:
 
Currently, DOME can only playback .wav and .ogg files so we use the former here.
<langsyntaxhighlight lang=ecmascript>import "dome" for Window, Process, Platform
import "graphics" for Canvas, Color
import "audio" for AudioEngine
Line 851:
}
 
var Game = AudioAlarm.new()</langsyntaxhighlight>
 
=={{header|XPL0}}==
Works on Raspberry Pi.
<langsyntaxhighlight lang=XPL0>int Time, I, J, Ch;
char FN(80), Ext;
[Text(0, "Number of seconds to wait? ");
Line 872:
DelayUs(Time * 1_000_000);
PlaySoundFile(FN);
]</langsyntaxhighlight>
 
=={{header|Yabasic}}==
<langsyntaxhighlight lang=Yabasic>input "How long to wait for (seconds): " sec
input "What file to play: " song$
wait sec
Line 881:
 
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 899:
//Atomic.sleep(time);
//System.cmd("mplayer "+file);
</syntaxhighlight>
</lang>
{{out}}
<pre>
10,333

edits