#!/bin/sh # # Revision notes: This is version 4.2-061607 (June 16, 2007) # Comments were cleaned up. The file conditions.txt is used for screen # output in both applications (spelled correctly), with a specially # modified text "festread.txt" intended for Festival to use. It has # purposely misspelled words so that Festival will pronounce them # a certain way. # # This is still beta grade, provisions for data "not available" and # "variable" in the winds description should be worked in. # # Credits: Started by kb9mwr, minor tweaks by kb9aln # # Description: # A script that grabs that current decoded (METAR style) local weather # observations. We do some magic to make it text to speech readable. # I'm using Cepstral to convert the text to speech, optionally you can use # festival. # #[custom-wxcond] #exten => s,1,Answer #exten => s,2,System(/usr/local/bin/get-conditions) #exten => s,3,Wait(2) #exten => s,4,MP3Play(/tmp/conditions.mp3) #exten => s,5,hangup # ########## # Clean-up ########## /bin/rm -f /tmp/metar.txt > /dev/null 2>&1 /bin/rm -f /tmp/forecast.txt > /dev/null 2>&1 /bin/rm -f /tmp/conditions.* > /dev/null 2>&1 /bin/rm -f /var/lib/asterisk/sounds/conditions.gsm > /dev/null 2>&1 # ############### # Get the METAR ############### #lynx -dump http://weather.noaa.gov/pub/data/observations/metar/decoded/KGRB.TXT > /tmp/metar.txt wget http://weather.noaa.gov/pub/data/observations/metar/decoded/KGRB.TXT -O /tmp/metar.txt > /dev/null 2>&1 wget http://weather.noaa.gov/pub/data/forecasts/city/wi/green_bay.txt -O /tmp/forecast.txt > /dev/null 2>&1 # ################### # Extract variables ################### TEMP1=`grep "Temperature" /tmp/metar.txt` TEMP=`echo $TEMP1 | cut -c13-15` SKY1=`grep "Sky conditions" /tmp/metar.txt` SKY=`echo $SKY1 | cut -c17-33` # # This determines if there is no wind at all ie. Calm. If it is, it sets a # flag. Cleaned up on 6/16/07 # CALM1=`grep "Wind" /tmp/metar.txt` CALM2=`echo $CALM1 | cut -d " " -f2` # if [ $CALM2 = "Calm:0" ]; then CALMFLAG=1; else CALMFLAG=0; fi # # if [ $CALMFLAG = 0 ]; then WIND1=`grep "Wind" /tmp/metar.txt`; WDIR1=`echo $WIND1 | cut -d " " -f4`; fi # # # Had to set WDIR1 to something even if there is no wind, otherwise # bash complains that there is no unary operator. # if [ $CALMFLAG = 1 ]; then WDIR1="0" fi # # Replacement of directions with non-abbreviated words. # This was updated 6/13/07 to include ENE, WNW, WSW and ESE. # if [ $CALMFLAG = 1 ]; then WDIR=" " fi # # if [ $WDIR1 = "SSE" ]; then WDIR="South South-East" fi # # if [ $WDIR1 = "ESE" ]; then WDIR="East South-East" fi # # if [ $WDIR1 = "SSW" ]; then WDIR="South South-West" fi # # if [ $WDIR1 = "WSW" ]; then WDIR="West South-West" fi # # if [ $WDIR1 = "NNE" ]; then WDIR="North North-East" fi # # if [ $WDIR1 = "ENE" ]; then WDIR="East-North-East" fi # # if [ $WDIR1 = "NNW" ]; then WDIR="North North-West" fi # # if [ $WDIR1 = "WNW" ]; then WDIR="West North-West" fi # # if [ $WDIR1 = "NE" ]; then WDIR="North-East" fi # # if [ $WDIR1 = "NW" ]; then WDIR="North-West" fi # # if [ $WDIR1 = "SE" ]; then WDIR="South-East" fi # # if [ $WDIR1 = "SW" ]; then WDIR="South-West" fi # # if [ $WDIR1 = "N" ]; then WDIR="North" fi # # if [ $WDIR1 = "S" ]; then WDIR="South" fi # # if [ $WDIR1 = "E" ]; then WDIR="East" fi # # if [ $WDIR1 = "W" ]; then WDIR="West" fi # # # Again we use the calm flag to test and make a decision. If the # flag is 1, it sets a null speed value. This is just to keep the # variable values filled with something in the script. # if [ $CALMFLAG = 1 ]; then WSPEED=" "; else WSPEED=`echo $WIND1 | cut -d " " -f8`; fi ## # ################# # Generate Output ################# # This section processes the Screen output for the terminal. # originally put it in for debugging.. # echo "The Current temperature is $TEMP degrees." >> /tmp/conditions.txt echo "Skies are $SKY." >> /tmp/conditions.txt # # Here is the conditional test and wind characteristics output to the # wxdisplay.txt file for the terminal output. # if [ $CALMFLAG = 1 ]; then echo "The Wind is Calm." >> /tmp/conditions.txt; else echo "The Wind is from the $WDIR at $WSPEED miles per hour." >> /tmp/conditions.txt; fi echo "Forecast for Green Bay is as follows." >> /tmp/conditions.txt tail -5 /tmp/forecast.txt | while read line; do echo "$line." | cut -c2-80 >> /tmp/conditions.txt done # # Now for visual output. This just dumps the conditions.txt # file to the console or a terminal window. This file is also read by # Cepstra. Festival reads a different file. # cat /tmp/conditions.txt # # Here is the output that appears in the file that Festival reads: # echo "Here is your weather report, Sir." >> /tmp/festread.txt echo "The Current temperature is $TEMP degrees." >> /tmp/festread.txt echo "Skies are $SKY." >> /tmp/festread.txt if [ $CALMFLAG = 1 ]; then echo "The Winde is Calm." >> /tmp/festread.txt; else echo "The Winde is from the $WDIR at $WSPEED miles per 'hour." >> /tmp/festread.txt; fi # ############################# # Convert to wav & misc stuff ############################# /opt/swift/bin/swift -f /tmp/conditions.txt -o /tmp/conditions.wav /usr/local/bin/lame --silent --scale 2.5 --abr 32 -m m -h /tmp/conditions.wav /tmp/conditions.mp3 #text2wave conditions.txt -o conditions.wav #/usr/local/share/festival/bin/festival --tts /tmp/festread.txt # #sox /tmp/conditions.wav -c1 -r8000 -w /var/lib/asterisk/sounds/conditions.gsm #chown "asterisk":"asterisk" /var/lib/asterisk/sounds/conditions.gsm #chmod 755 /var/lib/asterisk/sounds/conditions.gsm # # # exit 0 # # Exit with no errors #