|
Today's Deals Free:
VoIP Call Center Buyers Guide Free Newsletter: Voice & Data Convergence Free 90 Page IP Telephony Pocket Guide Search with Google Search this site with Google. Results may not include recent changes.
Last Changes Shoutbox
Server Stats
|
say datetimeSay a given date and time, returning early if any of the given DTMF digits are received on the channel. <time> is number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC). [format] is the format the time should be said in. See voicemail.conf (defaults to "ABdY 'digits/at' IMp"). Acceptable values for [timezone] can be found in /usr/share/zoneinfo. Defaults to machine default. Returns: failure: 200 result=-1 success: 200 result=0 digit pressed: 200 result=<digit> <digit> is the ascii code for the digit pressed. Go back to Asterisk AGI
Created by Adam Higerd, Last modification by Adam Higerd on Thu 13 of Oct, 2005 [15:46 UTC]
|
accurate talking clock example
#!/usr/bin/perl ############################################################################### # ACCURATE TALKING CLOCK script for use with ASTERISK PBX ############################################################################### # Created by Chris Walton July 22/2007; tested with Asterisk 1.4.6 # Use it, copy it, do what you wish with it! ############################################################################### # This script will generate a 1.5s beep at 0, 15, 30, and 45 seconds past # each minute. # It uses sub-second time delays in order to be as accurate as possible. # The time is annoumced in English at 11 seconds before the beep. # Warning "blips" play and 2 seconds and 1 second before the beep. ############################################################################### # After writing this simple test I put it to a simple test: # I tuned my shortwave radio to pick up the National Research Council of # Canada official time broadcasts. # I launched this script at the same time. # The beeps from the radio and the beeps from this program were very much in # sync. ############################################################################### # This script interfaces with the Asterisk AGI module. # It should be installed in /var/lib/asterisk/agi-bin. # To use, place the line: "exten => xxx,1,AGI(talking-clock.agi)" # in an appropriate context of the extensions.conf file. Replace "xxx" with # an unused extension of your choice. ############################################################################### # Requirements (nothing you don't already have) : # 1) Asterisk PBX software with AGI module enabled. # 2) Perl with "Time::HiRes" module. If you have perl, you probably have the # Time::HiRes module; it is part of the core perl distribution. # 3) The "at-tone-time-exactly" sound file which is part of the "extra-sounds" # tarballs available at http://ftp.digium.com/pub/telephony/sounds/ ############################################################################### # 1st PASS example... assume program starts at 5.5 seconds past the minute: # ---------------------------------------------------------------------------- # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # ->BLIP>BLIP>BLIP>BLIP>BLIP>BLIP>BLI>BLIP>BLIP>BEEP ############################################################################### # normal operation (loop): # ---------------------------------------------------------------------------- # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # BEEP--->SILENCE----->TIME_ANNOUNCEMENT_FOLLOWED_BY_SILENCE----->BLIP>BLIP>BEEP ############################################################################### use Time::HiRes ("usleep", "gettimeofday"); $blip="!523/20,!0/980"; # 20ms blip followed by 980ms silence. $beep="!415/1500"; # 1.5s beep. $silence="!0/500"; # 0.5s silence. # Turn off output buffering to stop dead lock. $|=1; sub status { # AGI function status is avaialbe on STDIN my $cmd=shift; my $status=<STDIN>; if ( $status !~ /^200 result=0/ ){ print STDERR "$cmd returned with bad status ($status)\n"; exit -1; } } # STDIN will initially contain assorted channel information. Discard it all. while(<STDIN>) { chomp; last unless ($_); } # Answer the channel print "ANSWER\n"; status("Exec Answer"); while (1){ my ($seconds,$microseconds)=gettimeofday; # Sleep until the next second rolls around. usleep (1000000-$microseconds); # Calculate number of seconds left before the beep. my $time_til_beep=14-($seconds%15); if ( $time_til_beep < 11 ){ # Insufficient time to announce the time; just play blips. # This should only occur on first pass. print "EXEC PlayTones ", ("$blip," x $time_til_beep), $beep, "\n"; status("Exec PlayTones"); # Sleep while the blips and beep are playing. usleep ( $time_til_beep * 1000000 + 1500000 ) ; } else { # We have sufficient time to announce what the time will be at the beep. $time_at_beep=$seconds + $time_til_beep + 1; # Sleep until 11 seconds before the beep and then announce the time. usleep ( ($time_til_beep - 11 ) * 1000000 ); print qq{STREAM FILE at-tone-time-exactly ""\n}; status("Stream File"); print qq{SAY DATETIME $time_at_beep "#" "IM'vm-and'S'seconds'\n}; status("Say DateTime"); # We need to get the time again because we don't know how long # the announcement took to play. ($seconds,$microseconds)=gettimeofday; # Now sleep until 2.5 seconds before the beep. my $delay=12500000 - $microseconds - (($seconds%15)*1000000) ; next if ( $delay < 0); # abort if annoucment took too long to play. usleep ($delay); # Now play two warning blips followed by the beep. # Preceeding the blips with .5s silence ensures the 1st blip is heard. print "EXEC PlayTones $silence,$blip,$blip,$beep\n"; status("Exec PlayTones"); # Sleep while the blips and beep are playing. usleep 4000000; } }