#!/bin/sh
# Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
# 
# Permission to use, copy, modify, and distribute this material 
# for any purpose and without fee is hereby granted, provided 
# that the above copyright notice and this permission notice 
# appear in all copies, and that the name of Bellcore not be 
# used in advertising or publicity pertaining to this 
# material without the specific, prior written permission 
# of an authorized representative of Bellcore.  BELLCORE 
# MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
# OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
# WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.

# Conversion from C shell to Bourne shell by Z-Code Software Corp.
# Conversion Copyright (c) 1992 Z-Code Software Corp.
# Permission to use, copy, modify, and distribute this material
# for any purpose and without fee is hereby granted, provided
# that the above copyright notice and this permission notice
# appear in all copies, and that the name of Z-Code Software not
# be used in advertising or publicity pertaining to this
# material without the specific, prior written permission
# of an authorized representative of Z-Code.  Z-CODE SOFTWARE
# MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
# OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",
# WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.

# This is to make metamail/showaudio do playback on the speaker, not the phone.
AUDIOSPEAKERFORCE=1; export AUDIOSPEAKERFORCE

if test -d /usr/sony
then
	dev=/dev/sb0
else
	dev=/dev/audio
fi

audiofile=$1

if test -f "$audiofile" -a -s "$audiofile"
then
	whatnext=1
else
	whatnext=0
fi

while true
do
	if test $whatnext -eq 1
	then
		echo ""
		echo "What do you want to do?"
		echo ""
		echo "1 -- Listen to recorded message"
		echo "2 -- Replace with a new recording"
		echo "3 -- All Done, Quit"
		read which
		case $which in
			1) cat $audiofile > $dev ;;
			2) whatnext=0 ;;
			3) exit 0 ;;
		esac
	fi
	echo -n "Press RETURN when you are ready to start recording: "
	read foo

	trap "kill -9 $! > /dev/null 2>&1" 1 2 15
	if test -z "$RECORD_AUDIO"
	then
		(/bin/cat < $dev > $audiofile) &
	else
		($RECORD_AUDIO > $audiofile) &
	fi
	echo -n "press RETURN when you are done recording: "
	read foo
	echo One moment please...
	/bin/sleep 1
	echo -n Killing recording job...
	/bin/kill -9 $! > /dev/null 2>&1
	whatnext=1
done
