Hardware Reference
In-Depth Information
4.
After the first #!/bin/sh line, you're free to put anything in this script. Just
keep in mind that you won't be able to use aliases here—you'll have to enter
full commands.
Here's an example record and playback script:
#!/bin/sh
#
# Auto-run script for Raspberry Pi.
# Use chmod +x ~/autorun.sh to enable.
PLAYORREC=P # Set to P for Playback or R for Record
INPUTFILE="playme.wav"
OUTPUTFILE="myrec.wav"
MICROPHONE="-t alsa plughw:1"
SPEAKERS="-t alsa plughw:0"
case "$PLAYORREC" in
P|p) sox ~/"$INPUTFILE" $SPEAKERS ;;
R|r) sox $MICROPHONE ~/"$OUTPUTFILE" ;;
*) echo "Set the PLAYORREC variable to P for Playback or R for
Record" ;;
esac
° The first #!/bin/sh line is called a shebang and is used to tell the
system that any text that follows is to be passed on to the default
shell (which is dash during boot and bash for logins on Raspbian)
as a script.
° The other lines starting with # characters are comments, used only to
convey information to anyone reading the script.
° The PLAYORREC variable is used to switch between the two operating
modes of the script.
° INPUTFILE is what will be played if we are in the playback mode, and
OUTPUTFILE is where we will record to if we are in the record mode.
° MICROPHONE and SPEAKERS lets us update the script easily for
different audio gadgets.
° The case block compares the character stored in the PLAYORREC
variable (which is P at the moment) against three possible cases.
If PLAYORREC contains a capital P or a lowercase p ), then run this sox
playback command.
 
Search WWH ::




Custom Search