Recording audio clips on a timer?
I'm working on a project that requires me to record a large number of 20-second audio clips (the file format is unimportant, as far as I'm aware). I would like to be able to do this without pressing a button to stop each recording—that is, I'm hoping there's a way that I can use a timer to stop recording automatically each time 20 seconds is up. Can I manage this in QuickTime? If not, I'm open to any suggestions the community may have. Thanks in advance.
Solution 1:
This is a sample script to try and fit the needs/wants you expressed. As coded it's going to make 3 five second recordings on your Desktop named "Recording_n.m4a" when 'n' in the name will be incremented automatically 1 to 3, e.g. "Recording_1.m4a", "Recording_2.m4a" etc. to whatever howMany is set to.
Open Script Editor and copy and paste the code below and press the "Compile" button.
set howMany to 3 -- The number of recordings to make.
set recordingNumber to 1 -- 'recordingNumber' is used to increment the recording number in the filename when exporting.
tell application "QuickTime Player"
activate
close (every document whose name contains "Untitled") saving no -- I set this just to have no other Untitled windows open when starting the recordings, especially if having broken out of the repeat loop.
repeat howMany times
set savePath to (the path to the desktop folder as text) & "Recording_" & recordingNumber & ".m4a"
set recording to new audio recording
start recording
delay 6 -- Add an additional second to the wanted value, e.g. for 20 second recording set delay to 21.
stop recording
export document "Untitled" in file savePath using settings preset "Audio Only"
delay 2 -- Set appropraite delay to allow export to complete.
close (every document whose name contains "Untitled") saving no
set recordingNumber to recordingNumber + 1 -- Increments recording number by one.
-- Close "Export Progress" window.
tell application "System Events" to click menu item "Hide Export Progress" of menu "Window" of menu bar 1 of process "QuickTime Player"
display dialog "Click OK or press Enter to start next recording."
end repeat
end tell
Run the script as is a time or two so you can see what it's doing and then you can change the value of howMany to the number of recordings you want/need to make, change the value of the first delay from '6' to '21' for a 20 second recording and the value of the second delay from '2' to e.g. '5'. The value of the second delay you'll need to determine ahead of time by setting the value of howMany to 1 or 2 and the value of the first delay from '6' to '21' so you have a 20 second recording to see how many seconds it takes to export. This value (of the second delay) can be higher then actually needed, say if you want a little break between recordings to catch your breath and collect your thoughts for the next recording, although there is another control in the form of a dialog message box between each recording.
Note the line display dialog "Click OK or press Enter to start next recording."
, it's there as a control mechanism to start the next recording or to break out of the repeat loop. There are many different of ways to code and accomplish a task like this and this is just meant to give you a starting framework to build upon if you want to use AppleScript to accomplish an automated task such as you've mentioned.
There is no error checking written into this script as is, meaning if the script is run a second time it will overwrite e.g. "Recording_1.m4a", "Recording_2.m4a" etc. So if you need to break out of the repeat loop by clicking "Cancel" in the dialog message box or "Stop" in the Script Editor, make sure you set recordingNumber
to the appropriate number, which would be the number used of the last exported file + 1. Also, the first close (every document whose name contains "Untitled") saving no
line will close any file opened in QuickTime Player whose name contains "Untitled" without saving it or prompting to be saved. It can be commented out by placing --
in front of it if you wish although if you broke out of the repeat loop you'll have to manually cleanup before restarting so you may want to leave it as is. Just when using this script only use QuickTime Player for the task at hand if you don't understand why I coded it this way.