Hardware Reference
In-Depth Information
If
PLAYORREC
contains a capital
R
or a lowercase
r
, then run this
sox
record command.
If
PLAYORREC
contains anything else or is left blank, then display
a hint to the user about it.
° The
sox
command is launched with the values of the variables
inserted as arguments, and we assume that the file specified is
located in the
pi
user's home directory.
5.
Once we've saved the
autorun.sh
script and exited the editor, there's one
last thing we need to do before we can actually run it. We need to give the
script executable permission with the
chmod
command:
pi@raspberrypi ~ $ chmod +x ~/autorun.sh
6.
Now we can give the script a test run:
pi@raspberrypi ~ $ ~/autorun.sh
If everything works fine now, it should also run fine when you reboot.
One major improvement we could do to the script is to have
tmux
start the playback
or recording process in the background. That way we'll be able to log in remotely to
check on
sox
as it runs. Simply change the two
sox
command lines as follows:
P|p) tmux new-session -s autostart -n $PLAYORREC -d "sox
~/\"$INPUTFILE\" $SPEAKERS" ;;
R|r) tmux new-session -s autostart -n $PLAYORREC -d "sox $MICROPHONE
~/\"$OUTPUTFILE\"" ;;
Here we tell
tmux
to create a new session named
autostart
, create a new window
named
P
or
R
depending on the mode, and to start in a detached state. Then we
specify the command we'd like to run inside the
tmux
session surrounded by double
quotes. Because
$INPUTFILE
and
$OUTPUTFILE
are also surrounded by double
quotes, we have to escape those characters by prefixing them with the
\
character.
The easiest way to temporarily disable the script when you don't need to play or
record anything on boot, is to remove the executable permission from the script:
pi@raspberrypi ~ $ chmod -x ~/autorun.sh