Sunday, July 22, 2012

Extracting audio recordings from Perseus wideband SDR files using AutoHotKey script language and TotalRecorder

One of the issues with using a wide-band SDR to record swaths of spectrum is finding the time to review the large amount of resulting recordings. I have attempted to automate some aspects of the review process by using AutoHotKey to script TotalRecorder to record the audio from the Perseus wave file as it plays back and automatically saving the resulting MP3 files with date, time and frequency of the recording. Through this script, for example, I can step through every frequency on the medium wave band from 540 to 1700 kHz and record, say, the one-minute top-of-the-hour of each frequency to it's own MP3 file. Then I can download those files to my iPod and listen to them while I exercise or work around the house rather than be chained to the computer listening via the Perseus interface. While any recording software can be made to work using this technique, I chose TotalRecorder due to its popularity in the radio hobby.

Here is the script (lines are commented to indicate things that I would have to edit each time I process a new Perseus file). I have commented the actions to describe what's happening.


; This script has ability to record when TOH is split between two different Perseus Recordings

; this script presumes that Perseus is running and mode (USB, SAM, etc), audio level and audio bandwidth set to desired values

; this also presumes that Total Recorder is running and File | New was executed to start a fresh recording

; sleep commands added to account for delays in responding to operations; increase if problems caused by delays occur
; sleep 1000 = one second delay

; Use AutoIt3 Window Spy program to verify button locations for mouse clicks - may change depending on screen resolution

  SetDefaultMouseSpeed, 10

;  WinGet,hwnd,ID,Perseus            ;get the Perseus windows handle
;  WinGet,TR_hwnd,ID,ahk_class TotalRecorderWndClass      ;get the TotalRecorder window class
;  MsgBox, %ID%

;Set the windows to the upper left corner to avoid hidden buttons

  WinMove,ahk_class TotalRecorderWndClass,,0,0 
  Freq:=530     ;set freq to start at bottom of MW band [change this if a different start freq is desired]
  Mouseclick,,63, 520     ;Put Perseus in Wav input mode if not already there
  sleep 1000


  MouseClick,,140,520                ;Perseus File open button
  Sleep 500
  SendInput {Raw} 1_000.wav          ;send Perseus wav file name [edit this for actual file name]
  Sleep 500
  Send {ENTER}
  Sleep 500
 ; MouseClick,,521,602               ;Advance playback bar to desired time mark [edit only first number in this] or leave commented out if desired to start at beginning of Perseus wav file
  Sleep 500
  MouseClick,,100,245,2              ;double click frequency to bring up frequency dialog
  sleep,1000                         ;wait until it is ready
  WinActivate,Frequency     ;get it active if it is positioned outside
  WinMove,Frequency,,10,200          ;Set the window to the upper left corner to avoid hidden buttons                         
  MouseClick,,12,202     ;Click into the input window
  send,%Freq%                        ;Set the center frequency
  MouseClick,,60,190                 ;click kHz
  sleep,500                          ;and wait for frequency adjustment
  MouseClick,,100,190                ;click close

  ;MouseClick,,65,595     ;press play (not needed if starting at beginning of file since Perseus autoplays new files)

  WinActivate,ahk_class TotalRecorderWndClass
  MouseClick,,480,315     ;start TotalRecorder recording

  sleep,90000                         ;sleep 90 seconds (1000 = 1 second) [edit this]

  MouseClick,,450,315     ;stop TotalRecorder
  sleep 500
  Send {ALT}     ;File
  Send F
  Send S     ;Save
  sleep 1000
  Filename = %Freq% 0000 UTC 9-12-2012`n    ; Template for naming files [edit this]
  sleep 1000
  ;msgbox %Filename%
  Send %Filename%
  sleep 1000
  ;Send {Enter}
  ;sleep 1000

  Send {ALT}              ;File
  Send F      
  Send N                              ;New
  sleep 500
  MouseClick,,25,595     ;press stop

  ;MsgBox %Freq%

  if Freq > 1700     ;if 1700 here then the last freq recorded is 1710 (1700 + 10 kHz step)
    MouseClick,,480,315     ;stop TotalRecorder
  Freq:= Freq+10                   ; step up 10 kHz
  ;MsgBox %Freq%



Copy the text between the snips, save it as a text file in Notepad or another text editor with the .ahk extension, then start both Perseus and TotalRecorder programs. Then run the AutoHotKey script to kick off the process. I caution that, while I made this work on my computer, running it on your system *may* result in some unexpected results - your system's screen resolution may be different so the location of buttons, etc. may not correspond to those in my example. Also, there is no "escape" from the script - if you want to stop it, you must actually terminate the AHK executable. I highly recommend using the AutoHotKey Spy program to view specific details like screen coordinates of button locations on your system.

In other words, this is not yet a turn-key solution.

I made a rather blurry YouTube video to demonstrate the process: