A baby monitor using a Raspberry Pi to send push notifications when triggered by noise
Bash




    arecord --device=hw:1,0 --format S16_LE --rate 44100 -d 2 /dev/shm/tmp_rec.wav ; sox -t .wav /dev/shm/tmp_rec.wav -n stat 2&gt;&amp;1 | grep "RMS     amplitude" | tail -c 9



You can use newlines instead of ; and after | to make it easier to see the separate commands:

    arecord --device=hw:1,0 --format S16_LE --rate 44100 -d 2 /dev/shm/tmp_rec.wav
    sox -t .wav /dev/shm/tmp_rec.wav -n stat 2&gt;&amp;1 |
        grep "RMS     amplitude" |
        tail -c 9




It's not clear to me why you're using /dev/shm rather than a pipe. Since you say you're not very familiar with bash, I wonder whether it's because you saw in the man page that sox requires a filename and didn't know that it's common for - to be used as a special filename to signify stdin. Untested, but on my reading of the man pages the following should work:

    arecord --device=hw:1,0 --format S16_LE --rate 44100 -d 2 |
        sox -t .wav - -n stat 2&gt;&amp;1 |
        grep "RMS     amplitude" |
        tail -c 9




I think the extraction of the amplitude could be more robust in two ways:


As a minor point, I suggest changing the regex to "RMS *amplitude" as a future-proofing precaution against the stats gaining a new stat with a longer name.
More importantly, tail -c 9 is a very bold assumption. The Python program uses strip(), so you don't care about leading whitespace. I propose replacing the tail with cut -d: -f2.




Final version of the bash script if you agree with all of my suggestions:

    arecord --device=hw:1,0 --format S16_LE --rate 44100 -d 2 |
        sox -t .wav - -n stat 2&gt;&amp;1 |
        grep "RMS *amplitude" |
        cut -d: -f2


Python



I don't have much to say here except that count and suppress looks to me to be at least one variable too many. If you replace with e.g. lines_to_suppress then if suppress becomes if lines_to_suppress &lt;= 0 and instead of incrementing count you decrement lines_to_suppress.

However, it might be clearest to just eliminate them both and replace


            count = 0
            suppress = True



with

            for _ in range(0, 5):
                sys.stdin.readline()
                print("Suppressing output")