[Asterisk-Users] Asterisk@home festival weather report
dean collins
dean at collins.net.pr
Fri Feb 18 17:04:24 MST 2005
This script was developed by Mark Johnson.
All I did (Dean Collins) was type up the instructions and make it easy to understand.
This Script will allow you to dial and extension number on your Asterisk at home V0.6 or later pabx and have it read you the weather for your city
How it does this is;
1/ When you dial your extension it causes the weather.agi script to run
2/ This makes the program net::ftp connect to the internet and download a text file from the weather.noaa.gov computer
3/ Festival the 'reads' this text file out to you
Net::ftp is now part of the perl library so you dont need to download this
Festival is installed from V0.6 or later of Asterisk at home so you dont need to download this
You need to work out which text file is suitable for yourself and modify the text below
my $custpath = "city/oh";
my $filename = "youngstown.txt";
The way I worked out what was suitable for me in NY, new_york was to log in via a ftp client and manually browse through to the appropriate folder. Now you have all the appropriate information - lets start.
So Step 1 - Copy the text below into Notepad and name it weather.agi
#!/usr/bin/perl -w
use Asterisk::AGI;
use Net::FTP;
my $AGI = new Asterisk::AGI;
my $server = "weather.noaa.gov";
my $basepath = "data/forecasts";
my $custpath = "city/oh";
my $filename = "youngstown.txt";
my @lines;
$AGI->exec('AGI',"festival-script.pl|\"Please wait while I get the latest forecast.\"");
$ftp = Net::FTP->new($server, Debug => 0)
or die "Cannot connect to $server: $@";
$ftp->login("anonymous","a\@b.com")
or die "Cannot login with anonymous/a\@b.com", $ftp->message;
$ftp->cwd("$basepath/$custpath")
or die "Cannot change working directory ", $ftp->message;
$ftp->binary;
$ftp->get($filename,"/tmp/$filename.$$") || die "Error while downloading /tmp/$filename.$$!!!\n", $ftp->message;
open(INPUT,"</tmp/$filename.$$") || die "Could not open /tmp/$filename.$$\n";
while(<INPUT>) {
if(grep(/^\./,$_)) {
chomp($_);
$_ =~ s/^\.//;
push(@lines,$_);
print "$_\n";
}
}
for($i = 0; $i < scalar(@lines); $i++) {
$AGI->exec('AGI',"festival-script.pl|\"$lines[$i]\"");
}
$AGI->exec('AGI',"festival-script.pl|\"Thank you and please call again!\"");
unlink("/tmp/$filesname.$$");
exit;
Step 2 - Copy the text below into Notepad and name it festival-weather-script.pl
#!/usr/bin/perl
#make a tts dir inside your sounds dir (as specified below)
#adjust the t2wp variable to point to your festival bin directory
use Asterisk::AGI;
use File::Basename;
use Digest::MD5 qw(md5_hex);
$AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my ($text)=@ARGV;
my $hash = md5_hex($text);
my $sounddir = "/var/lib/asterisk/sounds/tts";
my $wavefile = "$sounddir/"."tts-$hash.wav";
my $t2wp= "/usr/src/festival/bin/";
unless (-f $wavefile) {
open(fileOUT, ">$sounddir"."/say-text-$hash.txt");
print fileOUT "$text";
close(fileOUT);
my $execf=$t2wp."text2wave $sounddir/say-text-$hash.txt -F 8000 -o $wavefile";
system($execf);
unlink($sounddir."/say-text-$hash.txt");
}
$AGI->stream_file('tts/'.basename($wavefile,".wav"),1);
STEP 3 - Copy the 2 files into your /var/lib/asterisk/agi-bin directory
I use a program called winscp to do this [http://winscp.sourceforge.net/eng/index.php]
(it looks just like a ftp program but allows you to connect to asterisk and swap files between your windows pc and asterisk server)
STEP 4 - Create an extension number for your weather report.
I use Extension 850. The reason I use this is because in the asterisk at home installations AMP uses the 800 series for the Meetme rooms.
As this is similar to a Meetme function I'm going to put all of my festival extensions from 850 onwards.
Be carefule you dont have an extension on your pabx called 50 (because AMP will over write this Weather code with the meetme room number 850 for extension 50)
4/a) Log into Asterisk at home using a browser http://-asterisk-ip-adress/admin
Then click on Maintenance
Then click on ConfigEdit
Then click on Extensions.conf
Now you need to scroll down to where you see the [ext-meetme] context about ¾ of the way down the file
[ext-meetme]
exten => _8X,1,Answer
exten => _8X,2,Wait(1)
exten => _8X,3,GotoIf($[${CALLERIDNUM} = ${EXTEN:1}]?5:4)
exten => _8X,4,MeetMe2(${EXTEN}|sM)
exten => _8X,5,MeetMe2(${EXTEN}|asM)
etc
etc
etc
4/b) Then add the following text at the end of the context
exten => 850,1,Answer
exten => 850,2,AGI(weather.agi);
exten => 850,3,Hangup
that's it, reboot your pc, dial 850 and listen to the weather.
Any problems copy and paste your cli with any errors.
Cheers,
Dean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20050218/f107b627/attachment.htm
More information about the asterisk-users
mailing list