Audio alarm: Difference between revisions

Added Sidef
m (syntax highlighting fixup automation)
(Added Sidef)
 
(4 intermediate revisions by 4 users not shown)
Line 4:
=={{header|AutoHotkey}}==
Uses Run for maximum compatibility
<syntaxhighlight lang=AHK"ahk">Inputbox, seconds, Seconds, Enter a number of seconds:
FileSelectFile, File, 3, %A_ScriptDir%, File to be played, MP3 Files (*.mp3)
Sleep Seconds*1000
Line 10:
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f AUDIOALARM.AWK
BEGIN {
Line 35:
 
=={{header|Batch File}}==
<syntaxhighlight lang="dos">
@echo off
 
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"delphi">
program AudioAlarm;
 
Line 177:
 
=={{header|EchoLisp}}==
<syntaxhighlight lang="scheme">
(lib 'timer)
(lib 'audio)
Line 204:
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">Dim As Long sec
Dim As String song
Input "Delay in seconds: ", sec
Line 216:
 
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.
<syntaxhighlight lang="go">package main
 
import (
Line 266 ⟶ 356:
 
=={{header|Java}}==
<syntaxhighlight lang=Java"java">import com.sun.javafx.application.PlatformImpl;
import java.io.File;
import java.util.Scanner;
Line 307 ⟶ 397:
 
=={{header|JavaScript}}/{{header|HTML}}==
<syntaxhighlight lang=JavaScript"javascript"><title> AudioAlarm </title>
<script>
var a=prompt("Enter a number of seconds", "");
Line 316 ⟶ 406:
=={{header|Julia}}==
Works when the computer will play an MP3 file with the "play" command.
<syntaxhighlight lang="julia">print("Enter seconds to wait: ")
(secs = tryparse(Int, readline())) == nothing && (secs = 10)
 
Line 332 ⟶ 422:
=={{header|Kotlin}}==
For this to work on Ubuntu, 'glib' and 'libav-tools' need to be installed on your system.
<syntaxhighlight lang="scala">// version 1.1.51
 
import javafx.application.Application
Line 391 ⟶ 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.
<syntaxhighlight lang="lb">nomainwin
 
prompt "Delay in seconds"; sec$
Line 410 ⟶ 500:
luasdl2 and luafilesystem libraries required.
 
<syntaxhighlight lang="lua">SDL = require "SDL"
mixer = require "SDL.mixer"
lfs = require "lfs"
Line 429 ⟶ 519:
=={{header|Nim}}==
{{Trans|Go}}
<syntaxhighlight lang=Nim"nim">import os, strutils, terminal
 
var delay: int
Line 465 ⟶ 555:
requires mpg123 to be installed.
 
<syntaxhighlight lang="ocaml">let rec wait n = match n with
| 0 -> ()
| n -> Sys.command "sleep 1"; wait (n - 1);;
Line 481 ⟶ 571:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(notonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\AudioAlarm.exw
Line 703 ⟶ 793:
{{works with|Python|3.4.1}}
 
<syntaxhighlight lang="python">import time
import os
 
Line 714 ⟶ 804:
=={{header|Racket}}==
Racket does not currently have native mp3 support so this example uses system to call an external application.
<syntaxhighlight lang="racket">#lang racket
(display "Time to wait in seconds: ")
(define time (string->number (read-line)))
Line 724 ⟶ 814:
(sleep time)
(system* "/usr/bin/mpg123" (string-append file-name ".mp3")))</syntaxhighlight>
 
=={{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===
<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:'
Line 743 ⟶ 847:
 
===using spin===
<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:'
Line 760 ⟶ 864:
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
# Project : AudioAlarm
 
Line 779 ⟶ 883:
requires mpg123 to be installed.
 
<syntaxhighlight lang="ruby">puts "Enter a number of seconds:"
seconds = gets.chomp.to_i
puts "Enter a MP3 file to be played"
Line 786 ⟶ 890:
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}}
<syntaxhighlight lang="tcl">package require sound
 
fconfigure stdout -buffering none
Line 812 ⟶ 923:
 
Currently, DOME can only playback .wav and .ogg files so we use the former here.
<syntaxhighlight lang=ecmascript"wren">import "dome" for Window, Process, Platform
import "graphics" for Canvas, Color
import "audio" for AudioEngine
Line 855 ⟶ 966:
=={{header|XPL0}}==
Works on Raspberry Pi.
<syntaxhighlight lang=XPL0"xpl0">int Time, I, J, Ch;
char FN(80), Ext;
[Text(0, "Number of seconds to wait? ");
Line 875 ⟶ 986:
 
=={{header|Yabasic}}==
<syntaxhighlight lang=Yabasic"yabasic">input "How long to wait for (seconds): " sec
input "What file to play: " song$
wait sec
Line 886 ⟶ 997:
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.
<syntaxhighlight lang="zkl">hms :=Time.Date.parseTime(ask("Time to play mp3 file: "));
file:=ask("File to play: ") + ".mp3";
 
2,747

edits