#!/bin/sh ####################################################################### # description: Play the local WX conditions # input: /home/irlp/audio/conditions.mp3 ####################################################################### # # 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. # # ########## # 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 /tmp/festread.txt > /dev/null 2>&1 # ############### # Get the METAR ############### wget http://weather.noaa.gov/pub/data/observations/metar/decoded/KGRB.TXT -O /tmp/metar.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. # 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 # # Now for visual output. This just dumps the conditions.txt # file to the console or a terminal window. This file is also read by # Cepstral. 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 #sleep 1 #/usr/local/bin/lame /tmp/conditions.wav /home/irlp/audio/conditions.mp3 #sleep 1 #text2wave conditions.txt -o conditions.wav #/usr/local/share/festival/bin/festival --tts conditions.txt # # ####################################################################### # PLAY # ######## # If we are connected somewhere, go away #if [ -f $LOCAL/active ] ; then exit ; fi # Make us "busy" #touch $LOCAL/active rm -f $LOCAL/timeout >&/dev/null 2>&1 $BIN/forcekey # Play Report /opt/swift/bin/swift -f /tmp/conditions.txt $BIN/forceunkey rm -f $LOCAL/noid # Restore for IRLP #rm -f $LOCAL/active >&/dev/null 2>&1