Jump to content

Command line scripting with SoX

Recommended Posts

Hi All,

first time poster and absolute AutoIt beginner.... please be gentle! I'm trying to write a script to automate the Sox tool to record audio and I'm really excited by the possibilities of AutoIt. SoX runs from a command line and I can get my script to record OK but I'm having trouble stopping the recording. ProcessClose stops it by closing the DOS window but it also seems to corrupt the audio file for Windows Media player (other audio apps can open it though- I suspect mangled header information). The correct way to stop SoX from the command line is to send it CTRL+C. ControlSend seems good but the help file says "ControlSend is only unreliable for command prompts". I've done a lot of searching and a few others have had the problem with sending keystrokes to a non-active dos window but I can't understand a definitive answer. Is there a way to send a CTRL + C command to a non-active DOS window? How can find a simple way to stop SoX recording? Any assistance gratefully received.

Thank you.

Link to post
Share on other sites

I never heard of Sox before. It's a neat little program. You could actually write an entire GUI for it. It has a lot of options, so that would be time consuming. I wrote a very simplified on below. The documentation kind of says it doesn't really have a stop function when recording. One option is to send it a CTRL-C.

#include <GUIConstants.au3>

Global $sox = @ScriptDir & "\sox.exe"
Global $soxFolder = @ScriptDir

$Form1 = GUICreate("Form1", 510, 166)
$Input1 = GUICtrlCreateInput("", 60, 48, 369, 21)
$Button1 = GUICtrlCreateButton("Play", 200, 96, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Record", 80, 96, 75, 25, 0)
$Button3 = GUICtrlCreateButton("Stop", 325, 96, 75, 25, 0)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
$input = FileSaveDialog("choose", @DesktopDir, "(*.mp3)")
GUICtrlSetData($Input1, $input)
Case $Button2
Case $Button3
Send ("^c")


Func Play($song)
ShellExecute($sox, '"' & $song & '"' & " -d")

Func Rec()
ShellExecute($sox, " -d " & '"' & $soxFolder & "\" & @YEAR & "-" & @MON & "-" & @MDAY & "-" & @HOUR & "-" & @MIN & "-" & @SEC & ".wav" & '"')
Link to post
Share on other sites

Thanks so much for that... that's fantastic. It's the first SoX AutoIt recorder script I've seen anywhere... (maybe you're the first?!). I've learnt a lot from it. My next steps are to make the DOS window invisible, make the "record" button turn red when it's recording and to FTP the recorded file after stopping. I'll see how I go. I'm also curious to see if AutoIt can extract information from the running DOS window, such as the peak overload, headroom data recording running time. A peak level meter would be awesome. I'm hitting Google to see what I can get going- perhaps not possible but other might be interested too, so I'll report back.

Thaks again.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...