home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / bin / showaudio < prev    next >
Encoding:
Text File  |  1993-05-13  |  6.0 KB  |  206 lines

  1. #!/bin/csh -f
  2. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  3. # Permission to use, copy, modify, and distribute this material 
  4. # for any purpose and without fee is hereby granted, provided 
  5. # that the above copyright notice and this permission notice 
  6. # appear in all copies, and that the name of Bellcore not be 
  7. # used in advertising or publicity pertaining to this 
  8. # material without the specific, prior written permission 
  9. # of an authorized representative of Bellcore.  BELLCORE 
  10. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  11. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  12. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  13. #
  14.  
  15.  
  16. if (! $?METAMAIL_TMPDIR) then
  17.     set METAMAIL_TMPDIR=/tmp
  18. endif
  19.  
  20. # First, figure out which machine to play it on!
  21. set thishost=`hostname`
  22.  
  23. # Note that there are some special lines in here that only work at Bellcore,
  24. # Specifically involving phone playback from the machine "greenbush".
  25. # Everything should work fine at other sites, though
  26. set AUDIOBINDIR=/u/andrew/phone-sau/bin
  27. set AUDIOPHONEHOST=greenbush
  28. set AUDIOPHONEHOSTLONG=greenbush.bellcore.com
  29. set AUDIOLOGMAIL=andrew@thumper.bellcore.com
  30. set ORG="Bellcore"
  31. if ("$1" == "-p") then
  32.     set AUDIOPHONE=$2
  33.     shift
  34.     shift
  35. endif
  36. if ("$1" == "-s") then
  37.     set AUDIOSPEAKERFORCE = 1
  38.     shift
  39. endif
  40. if ($?AUDIOPHONE || $?AUDIOPHONEFORCE) then
  41.     goto playphone
  42. endif
  43. if (! -d $AUDIOBINDIR) then
  44.     set AUDIOSPEAKERFORCE=1
  45. endif
  46.  
  47. set STDINPUT=0
  48. if ("$1" == "-") then
  49.     set STDINPUT=1
  50.     shift
  51. endif
  52. if ($#argv < 1) then
  53.     set STDINPUT=1
  54. endif
  55.     
  56. if (! $STDINPUT && ! $?AUDIOSPEAKERFORCE && ! $?AUDIOPHONEFORCE) then
  57.     if ($?MM_NOTTTY) then
  58.     if ($MM_NOTTTY == 1) then
  59.         setenv MM_NOTTTY 0
  60.         xterm -e showaudio $*
  61.         exit 0
  62.     endif
  63.     endif
  64. choosehardware:
  65.     echo This program can display audio on the speakers of some workstations, 
  66.     echo "or (at some sites) it can call you on the telephone.  Please choose one:"
  67.     echo ""
  68.     echo "1 -- Use the computer's speaker"
  69.     echo "2 -- Call me on the telephone"
  70.     echo ""
  71.     echo -n "Which do you prefer (1 or 2)? "
  72.     set ans=$<
  73.     if ($ans == 2)  then
  74.     echo "OK, we'll use the telephone..."
  75.     set AUDIOPHONEFORCE=1
  76.     echo "In the future, you can avoid this question by setting the environment variable"
  77.     echo "AUDIOPHONEFORCE to 1"
  78.     goto playphone
  79.     else if ($ans == 1) then
  80.         echo "OK, Attempting to play the audio using your computer's speaker.."
  81.         set AUDIOSPEAKERFORCE=1
  82.     echo "In the future, you can avoid this question by setting the environment variable"
  83.     echo "AUDIOSPEAKERFORCE to 1"
  84.     else
  85.     echo "That is NOT one of your choices."
  86.     goto choosehardware
  87.     endif
  88. endif
  89.  
  90. set audiohost=$thishost
  91. if ($?DISPLAY) then
  92.     set audiohost=`echo $DISPLAY | sed -e 's/:.*//'`
  93.     if ($audiohost == "unix") set audiohost=$thishost
  94.     if ($audiohost == "") set audiohost=$thishost
  95. endif
  96. if ($?AUDIOHOST) then
  97.     set audiohost=$AUDIOHOST
  98. endif
  99.  
  100. if ($audiohost != $thishost) then
  101.     echo Sending audio to $audiohost...
  102.     if ($?MMS_AUDIO) then
  103.         if ($?STDINPUT) then
  104.             cat | mms -host $audiohost "show audio/basic" -
  105.         else
  106.             cat $* | mms -host $audiohost "show audio/basic" -
  107.         endif
  108.         exit 0
  109.     endif
  110.  
  111. # The next two lines are very inefficient, but not everyone has their path right for an rsh
  112.     pushd ~ >& /dev/null
  113.     set thisprog=`which showaudio`
  114.     popd >& /dev/null
  115.     if ($?STDINPUT) then
  116.         cat | rsh $audiohost $thisprog -s -
  117.     else
  118.         cat $* | rsh $audiohost $thisprog  -s -
  119.     endif
  120.     exit 0
  121. endif
  122.  
  123. if (-f /usr/sbin/sfplay) then
  124.     if ($#argv >= 1) then
  125.     exec /usr/sbin/sfplay -i mu-law chan 1 rate 8000 end $*
  126.     else
  127.     cat > ${METAMAIL_TMPDIR}/audio.$$
  128.     /usr/sbin/sfplay -i mu-law chan 1 rate 8000 end ${METAMAIL_TMPDIR}/audio.$$
  129.     rm ${METAMAIL_TMPDIR}/audio.$$
  130.     exit 0
  131.     endif
  132. else if (-d /usr/sony) then
  133.     set dev=/dev/sb0
  134. else if (-e /usr/bin/audioplay) then
  135. #  Solaris 2.0
  136.     /usr/bin/audioconvert -i raw,voice -f sun $* | /usr/bin/audioplay
  137.     exit $status
  138. else if (-e /bin/audioplay) then
  139. #  Solaris 2.0
  140.     /bin/audioconvert -i raw,voice -f sun $* | /bin/audioplay
  141.     exit $status
  142. else
  143.     set dev=/dev/audio
  144. endif
  145.  
  146. if (-w $dev) then
  147. echo Playing audio on $thishost using $dev, one moment please...
  148. if ($#argv >= 1) then
  149.         cat $* > $dev
  150. else
  151.         cat > $dev
  152. endif
  153. exit 0
  154. endif
  155.  
  156. playphone:
  157. if (-d $AUDIOBINDIR) then
  158.               set thisprog=`which showaudio`
  159.     if (! $?AUDIOPHONE) then
  160.         if ($?MM_NOTTTY) then
  161.         if ($MM_NOTTTY == 1) then
  162.             setenv MM_NOTTTY 0
  163.             xterm -e $thisprog $*
  164.             exit 0
  165.         endif
  166.         endif
  167.         echo This message contains audio, which can be sent to your telephone.
  168.         echo Please enter the telephone number at which you would like to hear this
  169.         echo -n "audio message as you would dial it from INSIDE ${ORG}:  "
  170.         set AUDIOPHONE=$<
  171.     endif
  172.     if ($thishost == $AUDIOPHONEHOST || $thishost == $AUDIOPHONEHOSTLONG) then
  173.         echo Calling Phone number $AUDIOPHONE
  174.         echo "You MUST SAY HELLO when you answer the phone, or you will not hear the message."
  175.         mail -s "showaudio: `whoami` called $AUDIOPHONE" $AUDIOLOGMAIL < /dev/null
  176.         if ($?STDINPUT) then
  177.             cat $AUDIOBINDIR/../GREET.au $* - | $AUDIOBINDIR/play -\# $AUDIOPHONE -
  178.         else
  179.             cat $AUDIOBINDIR/../GREET.au $* | $AUDIOBINDIR/play -\# $AUDIOPHONE -
  180.         endif
  181.         echo All done
  182.         exit 0
  183.     else
  184.         echo Trying to rsh to $AUDIOPHONEHOST to send audio via telephone
  185.         cat $* | rsh $AUDIOPHONEHOST $thisprog -p $AUDIOPHONE -
  186.         exit 0
  187.     endif
  188. endif
  189. echo ""
  190. echo This message contains an audio mesage, which can not currently be
  191. echo played on this type of workstation.   If you log into an appropriate 
  192. echo "machine (currently a SPARCstations or Sony News workstation)"
  193. echo and read this message there, you should be able to hear the audio
  194. echo message.  
  195. echo ""
  196. echo -n "Do you want to write the audio out to a file [y] ? "
  197. set ANS=$<
  198. if ("$ANS" =~ n* ||  "$ANS" =~ N* ) exit 0
  199. echo -n "File name:"
  200. set fname=$<
  201. cp $1 $fname
  202. if ($status == 0) echo Wrote file $fname
  203. exit 0
  204.  
  205.