asterisk at home festival weather configuration

MP3 Audio directly from NOAA! Updated URLs on 12-15-06

If you are in the San Diego NOAA Office area (and maybe others, check your regional NOAA Office homepage from, you can get an audio file of the current forecast for your zone and play it directly.

For the San Diego NOAA Office area, go to and click on the Audio selection under Forecasts. Get the URL of the audio file for your zone from the map.

Create an announcement in wav format from:
I like the UK-Audrey voice, but try some others too.
Make something like:
latest-forecast.wav "Please wait while I download the latest forecast"
select-weatherorvmc.wav "Press 1 for voicemail press 2 for the latest weather forecast"
You will have to convert the wav files from 16000Hz to 8000Hz and maybe speed them up a bit (135%) and reduce the volume (60%) before you use them. Put them in /var/lib/asterisk/sounds named latest-forecast.wav and select-weatherorvmc.wav

Add something like this to your extensions.conf (maybe in the [rans] section) to get the latest forecast when you dial whatever extension (like 865) that you choose.

My extensions.conf for audio weather:

exten => 865,1,Answer
exten => 865,2,Playback(latest-forecast)
exten => 865,3,System(/usr/bin/curl -s > /tmp/LAXSAFC42.mp3)
exten => 865,4,Wait(1)
exten => 865,5,MP3Player(/tmp/LAXSAFC42.mp3)
exten => 865,6,System(rm /tmp/LAXSAFC42.mp3 -f) 
exten => 865,7,Hangup

If you have trouble, make sure you have curl installed, change the path above if necessary. find / -type f -name "curl" will find your curl executable. I'm using MP3Player instead of Playback because I don't have a sound card in the Asterisk box so mpg123 fails when it tries to use /dev/dsp. I suppose there is a way to have a dummy dev, but I don't know how. If you do use Playback instead of MP3Player, don't use the .mp3 file extension in your extensions.conf.

You can also do something like this in extensions.conf to be able to dial in and select the weather forecast.

My extensions.conf for audio weather:

exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,DigitTimeout,5
exten => s,4,ResponseTimeout,9
;exten => s,5,Dial(${CONSOLE},20)
exten => s,5,Dial(IAX2/3030,20)
exten => s,6,Voicemail(u3030)
exten => a,1,Background(select-weatherorvmc) ; Select 1-Voicemail, 2-Weather, 3- )
exten => 1,1,Goto(rans,8500,1)      ; Goto VoicemailMain
exten => 2,1,Goto(rans,865,2)       ; Goto Weather Forecast
;exten => a,1,Playback(select-weatherorvmc) ; Testing
;exten => a,2,Goto(rans,865,2)       ; Goto Weather Forecast
exten => t,1,Hangup
exten => i,1,Playback(invalid)	
exten => i,2,Hangup

Sweet, Now I can get the surf report too! Thanks for the pointer and to the NOAA. Good to see my tax money going to something useful.

I never was able to make this agi/pl script work on my asterisk box, but I did come up with an alternative configuration that does not use agi or scripting. Here it is:

First log into with an ftp client and browse to the appropriate weather file for example for my weather file is

next create a bash file in your /usr/bin directory called convert
  1. !/bin/bash
/usr/bin/text2wave /tmp/weather.txt -F 8000 -o /tmp/weather.wav

make the file executable

chmod 755 /usr/bin/convert

next modify your extensions.conf

exten => *65,1,Answer 
exten => *65,2,Playback(national-weather-service)
exten => *65,3,System(/usr/bin/curl -s > /tmp/weather.txt)
exten => *65,4,Wait(1)
exten => *65,5,System(/usr/bin/convert)
exten => *65,6,Playback(/tmp/weather)
exten => *65,7,System(rm /tmp/weather.* -f)
exten => *65,8,Hangup

Reload your asterisk config
asterisk -rx reload

Dial *65 and listen to your weather report.

Any questions email me at with subject 'asterisk consulting'

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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 an extension number on your Asterisk@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 computer
  3. Festival then 'reads' this text file out to you

Net::ftp is now part of the perl library so you don't need to download this
Festival is installed from V0.6 or later of Asterisk@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.

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 = "";
my $basepath = "data/forecasts";
my $custpath = "city/oh";
my $filename = "youngstown.txt";

my @lines;

$AGI->exec('AGI',"|\"Please wait while I get the latest forecast.\"");

$ftp = Net::FTP->new($server, Debug => 0)
        or die "Cannot connect to $server: $@";

        or die "Cannot login with anonymous/a\", $ftp->message;

        or die "Cannot change working directory ", $ftp->message;


$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>) {
            ~np~if(grep(/^\./,$_)) {~/np~
                        ~np~$_ =~ s/^\.//;~/np~
                        print "$_\n";

foreach(@lines) {

$AGI->exec('AGI',"|\"Thank you and please call again!\"");



Step 2 - Copy the text below into a text editor (Notepad) and name it

 #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/bin/";
 unless (-f $wavefile) {
         open(fileOUT, ">$sounddir"."/say-text-$hash.txt");
         print fileOUT "$text";
         my $execf=$t2wp."text2wave $sounddir/say-text-$hash.txt -F 8000 -o $wavefile";

STEP 3 - Copy the 2 files into your /var/lib/asterisk/agi-bin directory
I use a program called WinSCP to do this. (It looks just like a ftp program but allows you to securely 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@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)

A. Log into Asterisk@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
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)


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

Thats it, reboot your pc (or just reload asterisk), dial 850 and listen to the weather.
Any problems copy and paste your cli with any errors.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

I got sick of using the weather of "nearest" city from noaa ftp site since it did not have file for my city. After couple of days of hit and trial (i am novice in perl/asterisk/agi) I finally got the real time weather for MY city working. This script uses the wonderful perl module developed by Mina Naguib (
Here are the steps
1) Go to
2) copy the link on upper right side for Weather-Underground-3.02.tar.gz
3) run following commands on your asterisk linux box

cd /tmp
gunzip Weather-Underground-3.02.tar.gz
tar -xvf Weather-Underground-3.02.tar
cd Weather-Underground-3.02
perl Makefile.PL
make test
make install
cd /var/lib/asterisk/agi-bin

4) now edit your weather.agi using your favourite edit to

  1. !/usr/bin/perl -w

use Asterisk::AGI;
use Weather::Underground;

my $AGI = new Asterisk::AGI;

$weather = Weather::Underground->new(
place => "94555",
debug => 0
) || die "Error, could not create new weather object: $@\n";

$arrayref = $weather->get_weather()
|| die "Error, calling get_weather() failed: $@\n";

$AGI->exec('AGI',"|\"The latest weather forecast for $arrayref->[0]->{pl
ace}. Press 1 to skip ahead.\"");

$currentWeather = "Current weather for $arrayref->[0]->{place} is as follows. Current temperature
is $arrayref->[0]->{temperature_fahrenheit} degrees fahrenheit or $arrayref->[0]->{temperature_celsius} de
grees celcius. Currently it is $arrayref->[0]->{clouds} and weather conditions are $arrayref->[0]->{condit
ions}. For today moonrise time is $arrayref->[0]->{moonrise}\n\n";


$AGI->exec('AGI',"|\"That concludes the extended weather forcast.\"");



5) make sure that you put your zip code instead of 94555 in above script and save it

Now that should get weather customized for your city and in real time (not some local cached file)

Mukesh Aggarwal

Here is another weather script using ATT's TTS and NOAA.

  1. !/usr/bin/perl -w
use Asterisk::AGI;
use LWP::Simple;
use URI::Escape;

use HTTP: :Request: :Common;

Remove the extra spaces between the colons.(tiki kept centering the text with out them)
use LWP::UserAgent;
use Net::FTP;

$AGI = new Asterisk::AGI;

my $server = "";
my $basepath = "data/forecasts";
my $custpath = "city/ks";
my $filename = "chanute.txt";

$ftp = Net::FTP->new($server,Debug => 0)
	or die "Cannot Connect to NOAA Server: $@";

	or die "Cannot login with anonymous";

	or die "invalid directory";


$ftp->get($filename,"$filename") || die "Error Downloading ";

my $command = "perl -i.old -ne 'print unless 1 .. 5' $filename";


open (MYFILE, 'chanute.txt');

while (<MYFILE>) {


$wt = $wt . "$_\n";


close (MYFILE);

$currentWeather = $wt;

my $url = '';
    my $req = HTTP::Request->new('POST', $url);
    $req->content('txt=' . uri_escape($currentWeather) .
    my $res = LWP::UserAgent->new->simple_request($req);

    unless ($res->is_success || $res->code == 301) {
       die "Error connecting to TTS server: " . $res->status_line . ".\n"; }

    if ($res->content !~ /can be found <A HREF=([^>]*)>here<\/A>/i) {
       die "Response from TTS server not understood. Odd.\n"; }

    my $wav_url  = "$1";
    my $wav_file = $1; # for use in saving to disk.
    $wav_file =~ s/.*?\/(\w+.wav)/$1/;
    getstore($wav_url, "/tmp/$wav_file") or
     die "Download of $wav_file failed: $!";

my $wCleanup = "sox /tmp/$wav_file -r 8000 -c 1 -s -w /var/lib/asterisk/sounds/weather.wav";


Stephen - RTS
Created by: dean.collins, Last modification: Tue 11 of Sep, 2012 (00:17 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+