#!/bin/bash #------------------------------------------- # GENERAL NOTES # #------------------------------------------- # This is a the old "simplex parrot" bash # script stripped down to simply record # captured audio that breaks a silence # level and save it in timestamped files. # # If you patch a radio/scanner into your # computer or Pi, you can have a set of # recordings with date-time stamps # for listening to later. #------------------------------------------- # Save in its own directory as scanner-record.sh # create a "record" directory there and then run: # # ./scanner-record.sh #------------------------------------------- # Note: # See the monitor.sh sister-script for ideas # on how to watch for new recordings and # then take action: # https://pastebin.com/CnS58d95 #------------------------------------------- # Use pavucontrol to select input and output # or however is easiest/best for your # working environment. # # Raspberry Pi may use alsa instead of # pulse. You'll have to configure things # with alsamixer or similar. It does seem # to use pulseaudio nicely when pulse is # installed. #------------------------------------------- # Code by Phillip J Rhoades (2024) #------------------------------------------- #------------------------------------------- # HARDWARE NOTES # #------------------------------------------- # When patching in from a Baofeng or such, # I use an HT with an APRS cable and a # mic/headphones splitter on one end # to patch the radio into a Linux computer # or a Raspberry Pi. The Pi will need a # cheap USB soundcard. A USB soundcard # could also help with ground issues # (buzzing) on computers/laptops. # # You'll have to adjust input and output # volumes on the computer and the output # volume on the radio/scanner. # # You could improve on this basic setup # in a number of ways but that's outside # the scope of this "simple" project. # # If you're reading this script in monospace # then this rough ASCII diagram of the setup # might help you get a clearer idea: # # -->[PC Mic In] # [HT]<-APRS->SPLIT-|| # <--[PC Sound Card Out] (NOT NEEDED) # # In some cases, a ground loop noise # isolator or two might help with buzzing # sounds between the computer and the HT. # # You can also use a cable that plugs into # the tiny speaker-out of the radio and converts # to the normal "headphone jack" of the computer # # Most scanners have a "headphone out" or # "speaker out" port that you can plug into # your computer mic port. You won't need # to deal with APRS cables etc in that case. #------------------------------------------- #------------------------------------------- # VARIABLE(S) TO CONTROL THINGS # #------------------------------------------- # In order to keep the size down # I convert the wav file to ogg in the # background. You could easily set that to # mp3 instead or you could skip conversion # and just keep the original wavs, if you # have plenty of disk space. # # Setting SAVERECS to 1 activates this # feature and setting SAVERECS to 0 # disables it. (2020/02/26) # If you just want to listen to the scanner # on your computer, you might not save the # recordings... #------------------------------------------- SAVERECS=1 SAVERECSDIR="./record" #------------------------------------------- # MORE "ELEGANT" EXITING # (but still pretty much a hammer) # # Trap ctrl-c and call ctrl_c() # to exit somewhat gracefully... #------------------------------------------- trap ctrl_c INT function ctrl_c() { if test -f "./recording.wav"; then rm recording.wav fi echo echo "#-----------------------------------" echo "# Terminating the scanner recorder " echo "#-----------------------------------" #------------------------------------------- # Kill the recorder and its parent process. # # Could issue shutdown -h instead in order # to shut down Linux/Pi computer completely. #------------------------------------------- kill -9 $PPID #shutdown -h now } #------------------------------------------- # REPEATER RECORDER LOOP # #------------------------------------------- # Loop until ctrl-c on keyboard or the # DTMF command to terminate the repeater #------------------------------------------- while [ 1 ]; do echo echo "#-------------------------------" echo "# WAITING FOR AUDIO INPUT:" echo "#-------------------------------" # Silent record rec -V1 -c1 recording.wav rate 64k silence 1 0.1 1% 1 3.0 1% trim 0 300 # Command for pass-through for scanner sound # while still recording a wav. # Some latency dependent on computer, but basically live. # Making the mic hot in alsa or pulse would have # less latency but other issues. #rec -V1 -c1 -t wav - rate 64k silence 1 0.1 1% 1 3.0 1% trim 0 300 |tee recording.wav |play -t wav - if test -f "./recording.wav"; then echo if [ $SAVERECS = 1 ]; then # The timestamp is YEAR-MONTH+DAYOFMONTH-HOURMINUTESECONDS (2024-03-21-231107) # Sorts better in an ls that way TIMESTAMP=$(date +"%Y-%m-%d-%H%M%S") mv recording.wav "$SAVERECSDIR/$TIMESTAMP.wav" #moving a file on the same filesystem is fast and cheap (ffmpeg -loglevel quiet -i "$SAVERECSDIR/$TIMESTAMP.wav" "$SAVERECSDIR/$TIMESTAMP.ogg"; rm "$SAVERECSDIR/$TIMESTAMP.wav") & #Takes time. Do in background else rm recording.wav #cleanup before restarting loop fi fi done