#!/usr/local/bin/zplay -X/bin/sh
#!/bin/sh

#
# play back incoming voice messages
#

# if you have a /dev/audio device available on your computer,
# set DEVAUDIO to "true" and use "#!/bin/sh" as the first line
# of this script.

#DEVAUDIO=true
DEVAUDIO=false

cd /usr/spool/voice/incoming
DIALOG=dialog
DONE=no

while [ $DONE = "no" ]; do
	if $DIALOG </dev/tty --clear --title "PLAY VOICE" \
		--menu "Pick a voice file to play" 20 51 14 \
		`ls -l voc* \
		| awk '{ printf("%s \042%s-%s-%s--%dk\042 ",$9,$6,$7,$8,$5/1024) }'` \
		2> /tmp/menu.tmp.$$; then

		choice=`cat /tmp/menu.tmp.$$`
		$DIALOG </dev/tty --title "PLAYING FILE" \
			--infobox "Playing $choice" 5 51
		if [ $DEVAUDIO = false ]
		then
			zplay -S -s $choice
		else
			adpcmtopvf -r610 < $choice | pvfspeed 1.2 | \
				pvftoau -ulaw > /dev/audio
		fi
		if $DIALOG </dev/tty --clear --title "DELETE FILE" \
			--yesno "Delete $choice?" 5 51; then
			rm $choice
		fi
	else
		$DIALOG --clear
		DONE=yes
	fi
	rm -f /tmp/menu.tmp.$$
done


