Book Image

Raspberry Pi for Secret Agents - Second Edition

By : Stefan Sjogelid
Book Image

Raspberry Pi for Secret Agents - Second Edition

By: Stefan Sjogelid

Overview of this book

Table of Contents (12 chapters)
Raspberry Pi for Secret Agents Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Bonus one line sampler


Let's wrap up the chapter with a trivial project that's got big pranking potential.

  1. First, make nine short samples, each sample being one second in length using the following command:

    pi@raspberrypi ~ $ sox -t alsa plughw:1 sample.wav trim 0 00:00:01 : newfile : restart
    
  2. Now, enter this one line sampler command and use your number keys 1 to 9 to trigger the samples and Ctrl + C to quit:

    pi@raspberrypi ~ $ while true; do read -n 1 -s; sox ~/sample00$REPLY.wav -d; done
    

This is a small piece of bash script where the commands have been separated with the; character instead of spreading over multiple lines. It starts off with a while true infinite loop, which makes the commands that follow repeat over and over again forever. The next command is read -n 1 -s, which reads one character from the keyboard and stores it in the REPLY variable. We then trigger the sox command to play the sample associated with the number by inserting the REPLY value as part of the filename.

When...