AllStar Weather Script

The AllstarLink software has had a weather script feature which would allow you to periodically download the weather from Underground, NWS, and other sources. It would then call the Google “Text-to-Speech” service and convert. Recently Google shut off this service and so the Allstar weather feature would no longer work.

There are many canned voice files with in the Allstar release so it is possible to build the weather announcement via these canned phrases and words.

Here’s the script I have added: download cur_wx To use it, in /usr/local/bin/getWxRpt_ug, comment out the calls to google_tts.py and add the following.
(cur_wx “$temp_f” “$wind_mph” “$wind_dir” “$precip_today_in” “$precip_1hr_in”
“$wind_gust_mph”)

The script will generate temp, wind, and rainfall(if any today) and append to node-id-long in /etc/asterisk/local. You can change rpt.conf to use this new node id. Also the *987 code can be modified to call the node-id-long.

#!/bin/bash
# pass wx cond and convert to speach 
# by n5tm

args=("$@")

SOUND_VAR_DIR=/var/lib/asterisk/sounds
ETC_DIR=/etc/asterisk/local

# parse each character into wx_value.gsm audio file 
parseStr(){
	string=$1
	INT=${1%.*}
        DEC=${1##*.}
	digit="digit-"
	unset chars
	declare -a chars
	while read -N 1
	do
    		chars[${#chars[@]}]="$REPLY"
	done <<<"$string"x
	unset chars[$((${#chars[@]} - 1))]
	unset chars[$((${#chars[@]} - 1))]

	echo "Array: ${chars[@]}"

	echo "Array length: ${#chars[@]}"
	INT=${string%.*}
        DEC=${string##*.}	

	if [ ${INT} -lt 20 ]; then
		cat ${SOUND_VAR_DIR}/digits/${INT}.gsm >> ${ETC_DIR}/wx_value.gsm
		if [[ $string == *"."* ]]; then
			if [ ${#DEC} -gt 1 ]; then
			   cat ${SOUND_VAR_DIR}/point.gsm ${SOUND_VAR_DIR}/digits/${DEC:0:1}.gsm >>  ${ETC_DIR}/wx_value.gsm
			   cat ${SOUND_VAR_DIR}/digits/${DEC:1:1}.gsm >>  ${ETC_DIR}/wx_value.gsm
			else
			   cat ${SOUND_VAR_DIR}/point.gsm ${SOUND_VAR_DIR}/digits/${DEC}.gsm >>  ${ETC_DIR}/wx_value.gsm
			fi
		fi

	else
	   if [ ${INT} -lt 100 ]; then
		if [ ${INT} -gt 20 ]; then
		    DECADE=$((INT/10*10))
		    MODULO=$((INT%10))
		    cat ${SOUND_VAR_DIR}/digits/${DECADE}.gsm >> ${ETC_DIR}/wx_value.gsm	
		    if [ ${MODULO} != 0 ]; then
		    	cat ${SOUND_VAR_DIR}/digits/${MODULO}.gsm >> ${ETC_DIR}/wx_value.gsm
		    fi
		    if [[ $string == *"."* ]]; then
                        cat ${SOUND_VAR_DIR}/point.gsm ${SOUND_VAR_DIR}/digits/${DEC}.gsm >>  ${ETC_DIR}/wx_value.gsm
                    fi
	
		else

	   	    for ((i=0; i < ${#chars[@]}; i++));
	     		do
				echo "${digit} '${chars[i]}'"
				if [ "${chars[i]}" = "." ]; then
					digit_file=${SOUND_VAR_DIR}/point.gsm
				else
					digit_file=${SOUND_VAR_DIR}/digits/${chars[i]}.gsm

				fi
				echo $digit_file
				cat ${digit_file} >> ${ETC_DIR}/wx_value.gsm
	     		done
		fi
	    fi	
	fi	
}

# main starts here
# first arg is temperature
# initialize wx_value.gsm with "temperature is currently"
echo number of Arguments: $#

cat ${SOUND_VAR_DIR}/wx/temperature.gsm ${SOUND_VAR_DIR}/is-currently.gsm > ${ETC_DIR}/wx_value.gsm
parseStr ${args[0]}   # add temp digits
cat ${SOUND_VAR_DIR}/degrees.gsm >> ${ETC_DIR}/wx_value.gsm    #add degrees to end
cat ${ETC_DIR}/wx_value.gsm > ${ETC_DIR}/cur_temp.gsm    # copy to cur_temp.gsm

# next wind direction
wind_dir=${args[2]}
cat ${SOUND_VAR_DIR}/wind.gsm ${SOUND_VAR_DIR}/letters/at.gsm > ${ETC_DIR}/wind_at.gsm

echo "arg[2]" $wind_dir
case "${wind_dir}" in
	'north') cat ${SOUND_VAR_DIR}/north.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
        'north north east') cat ${SOUND_VAR_DIR}/north.gsm ${SOUND_VAR_DIR}/wx/northeast.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm  ;;
	'north east') cat ${SOUND_VAR_DIR}/wx/northeast.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
        'east north east') cat ${SOUND_VAR_DIR}/east.gsm ${SOUND_VAR_DIR}/wx/northeast.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
	'east') cat ${SOUND_VAR_DIR}/east.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
        'east south east') cat ${SOUND_VAR_DIR}/east.gsm ${SOUND_VAR_DIR}/wx/southeast.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
        'south east')  cat ${SOUND_VAR_DIR}/wx/southeast.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
        'south south east') cat ${SOUND_VAR_DIR}/south.gsm ${SOUND_VAR_DIR}/wx/southeast.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
	'south') cat ${SOUND_VAR_DIR}/south.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
        'south south west') cat ${SOUND_VAR_DIR}/south.gsm ${SOUND_VAR_DIR}/wx/southwest.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
        'south west')  cat ${SOUND_VAR_DIR}/wx/southwest.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
        'west south west') cat ${SOUND_VAR_DIR}/west.gsm ${SOUND_VAR_DIR}/wx/southwest.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
	'west') cat ${SOUND_VAR_DIR}/west.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
        'west north west') cat ${SOUND_VAR_DIR}/west.gsm ${SOUND_VAR_DIR}/wx/northwest.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
        'north west') cat ${SOUND_VAR_DIR}/wx/northwest.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
        'north north west') cat ${SOUND_VAR_DIR}/north.gsm ${SOUND_VAR_DIR}/wx/northwest.gsm ${ETC_DIR}/wind_at.gsm > ${ETC_DIR}/wind_dir.gsm ;;
esac

# initialize wx_value.gsm with "wind.gsm" + "wind_dir.gsm"
cat ${ETC_DIR}/wind_dir.gsm > ${ETC_DIR}/wx_value.gsm
parseStr ${args[1]%.*}   # add wind digits strip decimal fraction
cat ${SOUND_VAR_DIR}/miles-per-hour.gsm >> ${ETC_DIR}/wx_value.gsm    #add mph to end
cat ${ETC_DIR}/wx_value.gsm > ${ETC_DIR}/cur_wind.gsm    # copy to cur_wind.gsm
# add gusts
cat ${SOUND_VAR_DIR}/wx/gusting-to.gsm > ${ETC_DIR}/wx_value.gsm
echo gusts to: ${args[5]}
parseStr ${args[5]%.*}
cat ${ETC_DIR}/wx_value.gsm >> ${ETC_DIR}/cur_wind.gsm

# check rainfall
echo rainfall today: ${args[3]}
if [ "${args[3]}" = "0.00" ]; then
	cat ${SOUND_VAR_DIR}/silence/1.gsm > ${ETC_DIR}/rain_today.gsm
else
	cat ${SOUND_VAR_DIR}/rainfall.gsm ${SOUND_VAR_DIR}/digits/today.gsm > ${ETC_DIR}/wx_value.gsm
	parseStr ${args[3]}
	cat ${ETC_DIR}/wx_value.gsm ${SOUND_VAR_DIR}/wx/inches.gsm > ${ETC_DIR}/rain_today.gsm
fi

#  concat temp pharse to end of node-id into node-id-long
cat ${ETC_DIR}/node-id.gsm ${SOUND_VAR_DIR}/repeater.gsm \
${SOUND_VAR_DIR}/silence/1.gsm ${ETC_DIR}/cur_temp.gsm \
${SOUND_VAR_DIR}/silence/1.gsm ${ETC_DIR}/cur_wind.gsm \
${SOUND_VAR_DIR}/silence/1.gsm ${ETC_DIR}/rain_today.gsm \
> ${ETC_DIR}/node-id-long.gsm