Advertisement
howtophil

scanner-record.sh

Mar 5th, 2024 (edited)
935
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.82 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #-------------------------------------------
  4. # GENERAL NOTES
  5. #
  6. #-------------------------------------------
  7. # This is a the old "simplex parrot" bash
  8. # script stripped down to simply record
  9. # captured audio that breaks a silence
  10. # level and save it in timestamped files.
  11. #
  12. # If you patch a radio/scanner into your
  13. # computer or Pi, you can have a set of
  14. # recordings with date-time stamps
  15. # for listening to later.
  16. #-------------------------------------------
  17. # Save in its own directory as scanner-record.sh
  18. # create a "record" directory there and then run:
  19. #
  20. # ./scanner-record.sh
  21. #-------------------------------------------
  22. # Note:
  23. # See the monitor.sh sister-script for ideas
  24. # on how to watch for new recordings and
  25. # then take action:
  26. # https://pastebin.com/CnS58d95
  27. #-------------------------------------------
  28. # Use pavucontrol to select input and output
  29. # or however is easiest/best for your
  30. # working environment.
  31. #
  32. # Raspberry Pi may use alsa instead of
  33. # pulse. You'll have to configure things
  34. # with alsamixer or similar. It does seem
  35. # to use pulseaudio nicely when pulse is
  36. # installed.
  37. #-------------------------------------------
  38. # Code by Phillip J Rhoades (2024)
  39. #-------------------------------------------
  40.  
  41. #-------------------------------------------
  42. # HARDWARE NOTES
  43. #
  44. #-------------------------------------------
  45. # When patching in from a Baofeng or such,
  46. # I use an HT with an APRS cable and a
  47. # mic/headphones splitter on one end
  48. # to patch the radio into a Linux computer
  49. # or a Raspberry Pi. The Pi will need a
  50. # cheap USB soundcard. A USB soundcard
  51. # could also help with ground issues
  52. # (buzzing) on computers/laptops.
  53. #
  54. # You'll have to adjust input and output
  55. # volumes on the computer and the output
  56. # volume on the radio/scanner.
  57. #
  58. # You could improve on this basic setup
  59. # in a number of ways but that's outside
  60. # the scope of this "simple" project.
  61. #
  62. # If you're reading this script in monospace
  63. # then this rough ASCII diagram of the setup
  64. # might help you get a clearer idea:
  65. #
  66. #                    -->[PC Mic In]
  67. # [HT]<-APRS->SPLIT-||
  68. #                    <--[PC Sound Card Out] (NOT NEEDED)
  69. #
  70. # In some cases, a ground loop noise
  71. # isolator or two might help with buzzing
  72. # sounds between the computer and the HT.
  73. #
  74. # You can also use a cable that plugs into
  75. # the tiny speaker-out of the radio and converts
  76. # to the normal "headphone jack" of the computer
  77. #
  78. # Most scanners have a "headphone out" or
  79. # "speaker out" port that you can plug into
  80. # your computer mic port. You won't need
  81. # to deal with APRS cables etc in that case.
  82. #-------------------------------------------
  83.  
  84. #-------------------------------------------
  85. # VARIABLE(S) TO CONTROL THINGS
  86. #
  87. #-------------------------------------------
  88. # In order to keep the size down
  89. # I convert the wav file to ogg in the
  90. # background. You could easily set that to
  91. # mp3 instead or you could skip conversion
  92. # and just keep the original wavs, if you
  93. # have plenty of disk space.
  94. #
  95. # Setting SAVERECS to 1 activates this
  96. # feature and setting SAVERECS to 0
  97. # disables it. (2020/02/26)
  98. # If you just want to listen to the scanner
  99. # on your computer, you might not save the
  100. # recordings...
  101. #-------------------------------------------
  102.  
  103. SAVERECS=1
  104. SAVERECSDIR="./record"
  105. #-------------------------------------------
  106. # MORE "ELEGANT" EXITING
  107. # (but still pretty much a hammer)
  108. #
  109. # Trap ctrl-c and call ctrl_c()
  110. # to exit somewhat gracefully...
  111. #-------------------------------------------
  112.  
  113. trap ctrl_c INT
  114.  
  115. function ctrl_c() {
  116.           if test -f "./recording.wav"; then
  117.                rm recording.wav
  118.           fi
  119.           echo
  120.           echo "#-----------------------------------"
  121.           echo "# Terminating the scanner recorder  "
  122.           echo "#-----------------------------------"
  123.  
  124.           #-------------------------------------------
  125.           # Kill the recorder and its parent process.
  126.           #
  127.           # Could issue shutdown -h instead in order
  128.           # to shut down Linux/Pi computer completely.
  129.           #-------------------------------------------
  130.  
  131.           kill -9 $PPID
  132.           #shutdown -h now
  133. }
  134.  
  135. #-------------------------------------------
  136. # REPEATER RECORDER LOOP
  137. #
  138. #-------------------------------------------
  139. # Loop until ctrl-c on keyboard or the
  140. # DTMF command to terminate the repeater
  141. #-------------------------------------------
  142.  
  143. while [ 1 ]; do
  144.           echo
  145.           echo "#-------------------------------"
  146.           echo "# WAITING FOR AUDIO INPUT:"
  147.           echo "#-------------------------------"
  148.           # Silent record
  149.           rec -V1 -c1 recording.wav rate 64k silence 1 0.1 1% 1 3.0 1% trim 0 300
  150.  
  151.           # Command for pass-through for scanner sound
  152.           # while still recording a wav.
  153.           # Some latency dependent on computer, but basically live.
  154.           # Making the mic hot in alsa or pulse would have
  155.           # less latency but other issues.
  156.           #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 -
  157.  
  158.  
  159.           if test -f "./recording.wav"; then
  160.                echo
  161.                if [ $SAVERECS = 1 ]; then
  162.                     # The timestamp is YEAR-MONTH+DAYOFMONTH-HOURMINUTESECONDS (2024-03-21-231107)
  163.                     # Sorts better in an ls that way
  164.                     TIMESTAMP=$(date +"%Y-%m-%d-%H%M%S")
  165.                     mv recording.wav "$SAVERECSDIR/$TIMESTAMP.wav" #moving a file on the same filesystem is fast and cheap
  166.                     (ffmpeg -loglevel quiet -i "$SAVERECSDIR/$TIMESTAMP.wav" "$SAVERECSDIR/$TIMESTAMP.ogg"; rm "$SAVERECSDIR/$TIMESTAMP.wav") & #Takes time. Do in background
  167.                else
  168.                     rm recording.wav #cleanup before restarting loop
  169.                fi
  170.           fi
  171. done
  172.  
Advertisement
Comments
  • howtophil
    59 days (edited)
    # text 0.65 KB | 0 0
    1. If you are watching a channel/frequency for activity but don't want to physically sit and listen, this can be helpful. It's a hack and slash of my "simplex repeater" script to simplify for use as a "record and loop" method.
    2.  
    3. I like leaving it running at night and waking up to "news" of things that happened for #police / #fire / #EMS / etc when I wake up.
    4.  
    5. Since it's a simple script, you can modify it to alert you via text (there are services that let you SMS from curl commands) or email you the recordings or any number of other things... Several old scanners and several USB soundcards could let you also tag the files with channel/frequency names... /shrug
Add Comment
Please, Sign In to add comment
Advertisement