Qlab Script: Trim audio files to where audio begins

538 views
Skip to first unread message

Kyle J Morgan

unread,
May 5, 2022, 1:07:32 PM5/5/22
to QLab
Hi all, 

It's dance recital time. With that, comes the infamous QLab scripts that save me a ton of time. I just recently started using the script from "Level Playing Field" in the cookbook and already it has saved me at least an hour worth of time. 

However, one script that I haven't found (and maybe I am not phrasing it correctly) is one that trims audio files to where audio begins. A lot of times, I get handed files that have 5 seconds of silence before and after the file. If I could find a script that would go through and set the trim points to where audio begins, that would also save an immense amount of time on my end. 

Any thoughts on this? Not even sure if this is doable, at that. 

micpool

unread,
May 5, 2022, 3:04:11 PM5/5/22
to QLab
Challenge Accepted!

Screen Shot 2022-05-05 at 19.42.37.png


set threshold to 0.005 --detect threshold value between 0 and 1
display dialog "Set the Start Times of selected audio cues to start of audio" & return & "This plays each cue until the start of the audio" & return & " The first 1/10 second of each cue will be audible!"
try
    tell application id "com.figure53.QLab.4" to tell front workspace
        set theselected to (selected as list)
        repeat with eachCue in theselected
            set the selected to eachCue
            set the start time of eachCue to 0
            set the post wait of cue "DETECT" to 0
            start cue "DETECT"
            start eachCue
            repeat until post wait of cue "DETECT" > threshold
                delay 0.01
            end repeat
            pause eachCue
            set the start time of eachCue to the (action elapsed of eachCue) - 0.1
            stop eachCue
            stop cue "DETECT"
        end repeat
    end tell
on error
    display dialog "Something Went Wrong!" & return & "Are selected cues all audio?"
end try

Cue DETECT is a network cue with an OSC query which sets its post wait to the  audio level of the selected (playing) cue (audio level linear scale 0 to 1)

/cue/DETECT/postWait #/cue/selected/liveAverageLevel/1 0 1#

In the attached screen recording  I have used quiet piano music with a threshold of 0.005, but you will need to experiment with this depending on what your typical material is

There may be other methods using ffmpeg or similar but this 'playing each cue in real time until the audio starts' is the only way I can think to do this without altering the actual files.

As always check thoroughly before using in a show situation, 

Mic 
TTT720p-HD 720p.mov

micpool

unread,
May 5, 2022, 3:06:17 PM5/5/22
to QLab
Workspace attached
(No Audio)
Set Start times to audio.qlab4

Sam Kusnetz

unread,
May 5, 2022, 3:19:49 PM5/5/22
to ql...@googlegroups.com
Mic, that is truly excellent.

-Sam
Sam Kusnetz (he/him) | Figure 53

Kyle J Morgan

unread,
May 5, 2022, 3:48:26 PM5/5/22
to QLab
This is absolutely incredible. This does exactly what I would want it to! 

Coupled with the audio leveler (which I now realize was also written by you), this will save me literally hours of going through tracks. 

Thank you so much! 

Alec Sparks

unread,
May 6, 2022, 12:19:19 PM5/6/22
to QLab
I'm a big fan of any script that uses a postwait field to store a generic non-time value. This is brilliant!

Alec

gui

unread,
Jun 24, 2022, 3:36:41 AM6/24/22
to QLab
Whaou !!!! Thank you
Message has been deleted

Taichee

unread,
Dec 29, 2022, 1:27:36 PM12/29/22
to QLab
Thank you!
 This is a great solution what I was looking for!!
We usually use AUTO-CUE function of the hardware rack players like TASCAM SS-CDR series since CD601 series generation. 
Professional audio player must have that function to begin the attack of simultaneously with hit the play button according to the director's count down cue. 

Manual trimming was torture for hundred songs. 

I hope someday Qlab has AUTO-CUE function like the TASCAM, old SONY, and PIONEER CDJ with the threshold setting but I believe this script would keep the position as the one of the solution. 

2022年6月24日金曜日 16:36:41 UTC+9 gui:

Taichee

unread,
Jan 2, 2023, 12:21:37 AM1/2/23
to QLab
Like this, do you have any idea to cut the end no-audio space automatically?

Some songs look finish earlier than displayed time remaining due to the blank at the end. I don't want to bother to trim manually... 

2022年12月30日金曜日 3:27:36 UTC+9 Taichee:

micpool

unread,
Jan 2, 2023, 6:27:14 PM1/2/23
to QLab
 On Monday, January 2, 2023 at 5:21:37 AM UTC Taichee wrote:
Like this, do you have any idea to cut the end no-audio space automatically?

This is more difficult. (if QLab could play the file backwards it would be straightforward)
You can specify how many seconds before the end of the file you want to search in and then use this script, which will load the cue to the end - number of seconds set to search set  in timeToScan play it and then set the end time to the time where the audio level is first  less than the threshold you set.

set timeToScan to 4 --number of seconds to search for silence at end

set threshold to 0.005 --detect threshold value between 0 and 1
display dialog "Set the end Times of selected audio cues to end of audio" & return & "This plays end of each cue until the end of the audio"

try
    tell application id "com.figure53.QLab.4" to tell front workspace
        set theselected to (selected as list)
        repeat with eachCue in theselected
            set the selected to eachCue
            set the end time of eachCue to 99999999

            set the post wait of cue "DETECT" to 0
            start cue "DETECT"
            load eachCue time ((duration of eachCue) - timeToScan)
            start eachCue
            delay 0.1

            repeat until post wait of cue "DETECT" < threshold
                delay 0.01
            end repeat
            pause eachCue
            set the end time of eachCue to the (action elapsed of eachCue) - 0.1

            stop eachCue
            stop cue "DETECT"
        end repeat
    end tell
on error
    display dialog "Something Went Wrong!" & return & "Are selected cues all audio?"
end try

Workspace attached

Obviously if you have something like a telephone and have your timeToScan set to 10 secs, its going to set the end to the first time an individual ring ends rather than the final silence, but for most music it may do what you want.


Mic
Set end times to audio silence.qlab4

Taichee

unread,
Jan 3, 2023, 1:01:49 AM1/3/23
to QLab
Thank you, Mic. First it looks like it was going well, but something is wrong....
What I found that here is a constraint that this end script only be able to execute when the start time setting was definitely zero timing.

If I run this END-TIME script after using the START-TIME script, the end time will be earlier by the start time offset.
In other words, After I run the START-TIME script for a song had 2 seconds gap at the beginning, then I ran this END-TIME script again, it will set the end time to 2 seconds earlier than the actual silence.

I would appreciate if you have any good ideas to solve.
2023年1月3日火曜日 8:27:14 UTC+9 micpool:

micpool

unread,
Jan 3, 2023, 6:10:19 AM1/3/23
to QLab
On Tuesday, January 3, 2023 at 6:01:49 AM UTC Taichee wrote:
If I run this END-TIME script after using the START-TIME script, the end time will be earlier by the start time offset.
In other words, After I run the START-TIME script for a song had 2 seconds gap at the beginning, then I ran this END-TIME script again, it will set the end time to 2 seconds earlier than the actual silence.
I would appreciate if you have any good ideas to solve.

Well, you have pretty much answered your own question!

Change the end time setting  line to:

set the end time of eachCue to the (action elapsed of eachCue) + (start time of eachCue)


(Action elapsed is the time since the cue started, so runs from the start time of the cue
The end time of the cue is an absolute time point within the duration of the whole audio file.)

Mic

Taichee

unread,
Jan 3, 2023, 10:34:13 PM1/3/23
to QLab
Thank you
 Solved! 

2023年1月3日火曜日 20:10:19 UTC+9 micpool:

Sooo

unread,
Feb 5, 2024, 8:40:04 AMFeb 5
to QLab
When I run this program in QLAB5, it does not work. Please help.

2023年1月4日水曜日 12:34:13 UTC+9 Taichee:

micpool

unread,
Feb 5, 2024, 1:41:38 PMFeb 5
to QLab
On Monday, February 5, 2024 at 1:40:04 PM UTC Sooo wrote:
When I run this program in QLAB5, it does not work. Please help.

Yes, you are right. The Network cue is behaving differently in QLab 5.3. (I think it will work fine in 5.2.4)
Not sure why at the moment.

Mic 

micpool

unread,
Feb 5, 2024, 4:04:57 PMFeb 5
to QLab
Hi
This script fixes it for QLab 5.3  (and will work with all other versions). I've also changed it to use the pre wait of a memo cue Numbered "RMS" to store the current sound level, so it's not using a live network cue to do this.

--This script requires a network cue  numbered "DETECT" sending the following OSC message at 30 fps for a duration of 10 s to port 53000 on localhost

-- /cue/RMS/postWait #/cue/selected/liveAverageLevel/1 0 1#

--This script requires a memo cue numbered "RMS" to store the current sound level


set threshold to 0.005 --detect threshold value between 0 and 1

display dialog "Set the Start Times of selected audio cues to start of audio" & return & "This plays each cue until the start of the audio" & return & " The first 1/10 second of each cue will be audible!"

try

tell application id "com.figure53.QLab.5" to tell front workspace

set theselected to (selected as list)

repeat with eachCue in theselected

set the selected to eachCue

set the start time of eachCue to 0

set the post wait of cue "RMS" to 0

delay 0.1

start eachCue

start cue "DETECT"

repeat until post wait of cue "RMS" > threshold

delay 0.01

end repeat

pause eachCue

set the start time of eachCue to the (action elapsed of eachCue) - 0.1

stop eachCue

stop cue "DETECT"

end repeat

end tell

on error

display dialog "Something Went Wrong!" & return & "Are selected cues all audio?"

end try


Screen recording and workspace attached.

Thanks for the heads up it had stopped working.

Mic
Thresholdv2.zip
Screen Recording 2024-02-05 at 20.48.58.mov
Reply all
Reply to author
Forward
0 new messages