Asterisk tips Airport Weather PHP

Speak AirPort Weather using TTS engine (Cepstral)

Updated 2007-Nov-15 Andy Wysocki awysocki (a) absoftware dot_here com

Dial an extenstion and have asterisk prompt for an Airport code it uses the Cepstrals TTS Engine to convert Text to Speach and write it to a WAV file, then
have Asterisk play that file.

  • This php applicaiton does NOT need app_cepstral installed
  • Modify the script for your local airport codes. I've set up some examples
  • airport.php

I made a tar file

Go Back to: Asterisk tips and tricks - Asterisk AGI

Here is the README from the TAR file:

AIRPORT 1.00 Nov 15, 2007
awysocki @

AIRPORT.PHP was developed after creating the weather.php agi module. This module
takes it a step further with prompting the user for a 3 digit airport code from
their keypad. It will look up within itself, for a known airport code. Then
access the's web site for the XML file for that airport and parse it
and TTS different fields from the XML. You can customize which files to play out
and if you want to pre or post text to what is TTS'ed. I'm not a DOC writer
so look at the code, I think PHP is somewhat easy to read.

One known problem with this is if the user hangs up and Asterisk kills the PHP module
then the /tmp/*.txt and tts/*.wav files could be left around


1.00 - Inital release 11/15/2007


You *MUST* have Cepstral installed with an 8kHz voice. I didn't want to have to
run the WAV files though SOX to convert it to 8K. I'm lazy ok!

Copy the airport.php file to the /var/lib/astersik/agi-bin directory. Make sure
the module can be executed by Asterisk. 'chmod a+x airport.php'

You can use ORD (673) to test with before you edit the PHP module

To add your own Airport codes that you want. No I wasn't going to figure out every
US airport code to Weather Observation Location. I don't have the time, and my
5 minutes of looking for a database didn't find any

Edit the PHP file and modify the $parm_airport_codes array. You need to know or look up
the air port code say for example Orlando (MCO) then use the web site to look up Florida, Find Orland, FL
and get its Observation Location code In this case KMCO Edit the table to add
your airport

'MCO' => 'KMCO',

Yes I know that in the lower 48 that all the Airport code just have K in front of them
for their observation code, But HI and AK don't follow that rule, they start with P

To modify which XML fields to use, its best to pull and XML file,
and look at it to see which fields you want read back to you. Once you know you can
edit the $parm_weather_say variable. The format of this field is

field_name:text to say before field:text to say after field

Lets take the location field, you can just add location to the string separated by |
character. So if you wanted it spoken twice you can change the parm_weather_say
variable to


To add something in front of the field, just use.

location:This is the location field|location

To add something in front and after juse use

location:This is the start:this is the end|location

Play with it, or e-mail if your question.

Create or verify that the /var/lib/asterisk/sounds/tts directory is there so the
swift application can create the WAV files where asterisk can read them.

Modify your extensions.conf file to create a new extension to call for weather

exten => 650,1,Answer
exten => 650,n,AGI(weather.php)
exten => 650,n,hangup

Reload your dial plan within asterisk, use the command

Asterisk> dialplan reload


Things that can go wrong, Cepstral is not installed. You can test this alone with
the command

swift -o test.wav "This is a test"

If that works then try with your 8kHz voice file, change the william to the voice
name you downloaded and installed.

swift -o test.wav -n william-8kHz "This is a test"

If this works, make sure you have PHP installed on your system.

php -v

Other options is to turn on debugging in the PHP module
set the variable in the PARM section


If you hear the SOMETHING HAS GONE TERRIBLY WRONG then check that you created
the TTS directory under the sounds directory of Asterisk

Good luck


"Q1 - I call in and don't hear anything"

A1 - There can be lots of issues here, Check that the PHP script in the cgi-bin directory has the execute bit on. check that the php file is formatted for unix. (use dos2unix command) and last, turn on the parm_debug_on option and look at the log file created by the PHP file. It should help you out, if its not created then check with Asterisk as to why it may not be calling the script

Any other problems e-mail me and as time permits I will help you out

See Also my other scripts:
Asterisk tips Wake-Up Call PHP - Asterisk tips Weather PHP
Created by: awysocki, Last modification: Fri 16 of Nov, 2007 (04:36 UTC)
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+