Code/AudioClip Recorder: Difference between revisions
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 10: | Line 10: | ||
Audio Clip Recorder: | Audio Clip Recorder: | ||
<pre> | <pre> | ||
tell application "QuickTime Player" | with timeout of 600 seconds | ||
tell application "QuickTime Player" | |||
activate | |||
new audio recording | |||
start document 1 | |||
set question to display dialog "Recording started" buttons {"Stop recording", "Save Recording"} | |||
set answer to button returned of question | |||
stop document 1 | |||
end tell | if answer is equal to "Save Recording" then save document 1 | ||
end tell | |||
end timeout | |||
</pre> | </pre> | ||
Audio Clip Crossfading Playback: | Audio Clip Crossfading Playback: | ||
<pre> | <pre> | ||
set kSpeakers to 0 | |||
--sets how long in seconds between each step in the fade | --sets how long in seconds between each step in the fade | ||
set fadeDelay to 0.1 | set fadeDelay to 0.1 | ||
set kScriptCommand_PLAY_PAUSE to 1 | set kScriptCommand_PLAY_PAUSE to 1 | ||
set kScriptCommand_STOP to 2 | set kScriptCommand_STOP to 2 | ||
-- | --Get current audio volume from kJams | ||
tell application "kJams Pro" to set kJamsMaxVolume to get volume kSpeakers | |||
--set QuickTime Volume maximum. Change to whatever value you want (0-1) | |||
set QuickTimePlayerMaxVolume to 1 | set QuickTimePlayerMaxVolume to 1 | ||
-- Number of steps in fade | |||
set fadeSteps to 20 | |||
--sets how much in percentage the volume is decreased per step | |||
set kJFadeStep to kJamsMaxVolume / fadeSteps | |||
set QTfadeStep to QuickTimePlayerMaxVolume / fadeSteps | |||
--this is the minimum volume setting | --this is the minimum volume setting | ||
set MinVolume to 0 | set MinVolume to 0 | ||
| Line 44: | Line 49: | ||
play document 1 | play document 1 | ||
repeat until (kJamsVolume ≤ 0 and audio volume of document 1 ≥ QuickTimePlayerMaxVolume) | repeat until (kJamsVolume ≤ 0 and audio volume of document 1 ≥ QuickTimePlayerMaxVolume) | ||
if QuickTimePlayerVolume is less than QuickTimePlayerMaxVolume then set QuickTimePlayerVolume to (QuickTimePlayerVolume + | if QuickTimePlayerVolume is less than QuickTimePlayerMaxVolume then set QuickTimePlayerVolume to (QuickTimePlayerVolume + QTfadeStep) | ||
set kJamsVolume to (kJamsVolume - | set kJamsVolume to (kJamsVolume - kJFadeStep) | ||
set the audio volume of document 1 to QuickTimePlayerVolume | set the audio volume of document 1 to QuickTimePlayerVolume | ||
tell application "kJams Pro" to set volume kSpeakers level kJamsVolume | tell application "kJams Pro" to set volume kSpeakers level kJamsVolume | ||
| Line 52: | Line 57: | ||
set isPlaying to playing of document 1 | set isPlaying to playing of document 1 | ||
set secondsToFade to | set secondsToFade to fadeSteps * fadeDelay | ||
set endingTime to (duration of document 1) - 2 * secondsToFade | set endingTime to (duration of document 1) - 2 * secondsToFade - 10 * fadeDelay | ||
set question to display dialog "Stop Playback?" buttons {"Stop Playback"} default button 1 giving up after endingTime | set question to display dialog "Stop Playback?" buttons {"Stop Playback"} default button 1 giving up after endingTime | ||
repeat while isPlaying | repeat while isPlaying | ||
repeat until (QuickTimePlayerVolume ≤ 0) | repeat until (QuickTimePlayerVolume ≤ 0) | ||
set QuickTimePlayerVolume to (QuickTimePlayerVolume - | set QuickTimePlayerVolume to (QuickTimePlayerVolume - QTfadeStep) | ||
set the audio volume of document 1 to QuickTimePlayerVolume | set the audio volume of document 1 to QuickTimePlayerVolume | ||
delay fadeDelay | delay fadeDelay | ||
Latest revision as of 07:10, 2 July 2010
I was inspired by a thread in the forum about the cross fader script. I never use it, mostly because I do not have any free spots to allow for intermission music. But what I DO do is record little snippets of people singing, and play them back after they finish, while I am waiting for the next singer to fight their way to the mic. I have to time the recording to give me a buffer so that I can use the mixer to fade them in and out, and sometimes it can get a bit rough, with sudden, loud beginnings or abrupt endings. So I wrote this pair of scripts to automate the process. The first is a simple script to tell QuickTime to record the current input channel. You can set it to internal mic or (preferably) the line in (you'll need to run a line from your mixer to the microphone input of your mac. Sorry, I don't do Windows scripting. Someone else will have to take care of that, once the Windows version comes out!) You have the option after the recording is done to save the recording to disk if you want a permanent copy. This is not necessary, even for the next part.
The second script then automates the playback. Activate the script and it will fade out the current song (usually at the end) in kJams, and fade in the most recent recording. You can either let it play out, or you can stop playback early, in either case, it will fade back out, reset the volume in kJams, close the audio recording window, and bring kJams to the frontmost application. (Note: There are still some issues, namely the fact that QT currently does not remove the item after it is recorded, but instead saves it as "audio recording <x>.mov" in the Movies folder. I have tried to remove this file in the playback script, but have yet to figure it out, so the option to save is almost redundant. Even so, having that option allows you to name the file, and just go in and delete all the "audio recording <x>.mov" files without previewing them. I hope to fix this shortly.
Here is the code. Hope someone finds this useful.
Audio Clip Recorder:
with timeout of 600 seconds
tell application "QuickTime Player"
activate
new audio recording
start document 1
set question to display dialog "Recording started" buttons {"Stop recording", "Save Recording"}
set answer to button returned of question
stop document 1
if answer is equal to "Save Recording" then save document 1
end tell
end timeout
Audio Clip Crossfading Playback:
set kSpeakers to 0
--sets how long in seconds between each step in the fade
set fadeDelay to 0.1
set kScriptCommand_PLAY_PAUSE to 1
set kScriptCommand_STOP to 2
--Get current audio volume from kJams
tell application "kJams Pro" to set kJamsMaxVolume to get volume kSpeakers
--set QuickTime Volume maximum. Change to whatever value you want (0-1)
set QuickTimePlayerMaxVolume to 1
-- Number of steps in fade
set fadeSteps to 20
--sets how much in percentage the volume is decreased per step
set kJFadeStep to kJamsMaxVolume / fadeSteps
set QTfadeStep to QuickTimePlayerMaxVolume / fadeSteps
--this is the minimum volume setting
set MinVolume to 0
tell application "QuickTime Player"
set QuickTimePlayerVolume to MinVolume
set kJamsVolume to kJamsMaxVolume
tell application "kJams Pro" to set volume kSpeakers level kJamsMaxVolume
set the audio volume of document 1 to MinVolume
play document 1
repeat until (kJamsVolume ≤ 0 and audio volume of document 1 ≥ QuickTimePlayerMaxVolume)
if QuickTimePlayerVolume is less than QuickTimePlayerMaxVolume then set QuickTimePlayerVolume to (QuickTimePlayerVolume + QTfadeStep)
set kJamsVolume to (kJamsVolume - kJFadeStep)
set the audio volume of document 1 to QuickTimePlayerVolume
tell application "kJams Pro" to set volume kSpeakers level kJamsVolume
delay fadeDelay
end repeat
set isPlaying to playing of document 1
set secondsToFade to fadeSteps * fadeDelay
set endingTime to (duration of document 1) - 2 * secondsToFade - 10 * fadeDelay
set question to display dialog "Stop Playback?" buttons {"Stop Playback"} default button 1 giving up after endingTime
repeat while isPlaying
repeat until (QuickTimePlayerVolume ≤ 0)
set QuickTimePlayerVolume to (QuickTimePlayerVolume - QTfadeStep)
set the audio volume of document 1 to QuickTimePlayerVolume
delay fadeDelay
end repeat
stop document 1
set isPlaying to playing of document 1
end repeat
close document 1
tell application "kJams Pro"
docommand kScriptCommand_STOP
set volume kSpeakers level kJamsMaxVolume
activate
end tell
end tell