#!/bin/sh

audiofile=$1

trap 'kill -9 $recordpid; rm -f /tmp/audio.$$; exit' 2

hosttype=`uname`
case $hosttype in
IRIX|SunOS|News)
	;;
*)
	cat <<\+
There is currently no way in which you can record audio on this type of
workstation.  If you log into an appropriate machine (currently a
SPARCstation, Sony News workstation, or Silicon Graphics Personal Iris or
Iris Indigo), you should be able to record a message.
+
	exit 1
	;;
esac

while :
do
	echo $n "Press RETURN when you are ready to start recording: $c"
	read answer

	if [ "${RECORD_AUDIO+defined}" = defined ]
	then
		$RECORD_AUDIO > $audiofile &
	else
		case $hosttype in
		IRIX)
			recordaiff -n 1 -s 16 -r 8000 /tmp/audio.$$ &
			;;
		SunOS)
			cat /dev/audio > $audiofile &
			;;
		News)	# XXX Is this Sony News?
			cat /dev/sb0 > $audiofile &
			;;
		esac
	fi

	recordpid=$!

	echo $n "Press RETURN when you are done recording: $c"
	read answer

	echo "One moment please..."
	sleep 1
	echo "Killing recording job..."
	kill -2 $recordpid
	wait
	if [ $hosttype = IRIX ]
	then
		sfconvert /tmp/audio.$$ $audiofile -o mulaw >/dev/null
		rm -f /tmp/audio.$$
	fi

	while :
	do
		cat << \+

What do you want to do?

1 -- Listen to recorded message
2 -- Replace with a new recording
3 -- All Done, Quit
+

		read answer
		case $answer in
		1)
			showaudio $1
			;;
		2)
			break
			;;
		3)
			exit
			;;
		esac
	done
done
