Batch split 35 separate 45 minute files into "3" 15 minute files each?
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Batch split 35 separate 45 minute files into "3" 15 minute files each?
Is there a way to open up all 35 files in Audacity (45 minutes each) and split them up into 3 files of 15 minutes each for *all* files then export it all to .wav in one folder?
-
billw58
- Forum Staff
- Posts: 5601
- Joined: Wed Aug 12, 2009 2:10 am
- Operating System: macOS 10.15 Catalina or later
Re: Batch split 35 separate 45 minute files into "3" 15 minute files each?
By "files" do you mean you have 35 Audacity projects or 35 WAV files?
This can be done with Macros, but the exact method depends on what you're starting with.
-- Bill
This can be done with Macros, but the exact method depends on what you're starting with.
-- Bill
Re: Batch split 35 separate 45 minute files into "3" 15 minute files each?
Hey Bill, most are WAV files and some are m4a, but I imagine the operation would be the same? I was thinking it would require some kind of scripting, like keyboard maestro or similar, it's nice that Audacity has that built in (new to it).
I just realized the files need to be under "9" minutes each now, but they don't have to be precisely cut on any transients or silence, just at 9 minute increments. I'm not a script wizard, is this one easy to macro up?
I just realized the files need to be under "9" minutes each now, but they don't have to be precisely cut on any transients or silence, just at 9 minute increments. I'm not a script wizard, is this one easy to macro up?
-
billw58
- Forum Staff
- Posts: 5601
- Joined: Wed Aug 12, 2009 2:10 am
- Operating System: macOS 10.15 Catalina or later
Re: Batch split 35 separate 45 minute files into "3" 15 minute files each?
These macros work. They may not be optimum - perhaps someone with more experience with macros could improve on them.
They should get you started. There are three, called "First Chunk". "Second Chunk" and "Third Chunk". You'll need to make two more ("Fourth Chunk" and "Fifth Chunk", and perhaps "Sixth Chunk" if your input files are over 45 minutes but less than 54 minutes).
To install these go to the Audacity settings folder, which is at ~/Library/Application Support/audacity. There should be a "Macros" folder there. Download the attached macro files and drag them into that folder. They should then show up in Audacity's Macros dialog.
You'll need to run each macro on the set of files. The macro "First Chunk" will export the first 9 minutes. The macro "Second Chunk" will export the second 9 minutes, etc. If the input file is named "myfile.mp3", the first exported file will be named "myfile.wav", the second file will be named "myfile001.wav", etc.
Audacity Macros have no if-then testing ability, so it is possible to export empty WAV files if the input file is shorter than expected.
This manual page explains how to apply macros to files.
-- Bill
EDIT: See better solution in message below.
They should get you started. There are three, called "First Chunk". "Second Chunk" and "Third Chunk". You'll need to make two more ("Fourth Chunk" and "Fifth Chunk", and perhaps "Sixth Chunk" if your input files are over 45 minutes but less than 54 minutes).
To install these go to the Audacity settings folder, which is at ~/Library/Application Support/audacity. There should be a "Macros" folder there. Download the attached macro files and drag them into that folder. They should then show up in Audacity's Macros dialog.
You'll need to run each macro on the set of files. The macro "First Chunk" will export the first 9 minutes. The macro "Second Chunk" will export the second 9 minutes, etc. If the input file is named "myfile.mp3", the first exported file will be named "myfile.wav", the second file will be named "myfile001.wav", etc.
Audacity Macros have no if-then testing ability, so it is possible to export empty WAV files if the input file is shorter than expected.
This manual page explains how to apply macros to files.
-- Bill
EDIT: See better solution in message below.
- Attachments
-
- First Chunk.txt
- (48 Bytes) Downloaded 65 times
-
- Second Chunk.txt
- (81 Bytes) Downloaded 40 times
-
- Third Chunk.txt
- (82 Bytes) Downloaded 36 times
Re: Batch split 35 separate 45 minute files into "3" 15 minute files each?
I was interested to see what you would come up with Bill.
I agree, there's no really elegant way to do this with normal Macros.
The best solution that I came up with, was to create a "Nyquist Macro", and use it in a normal macro.
Normal Macros have the convenience that they can automatically run through a list of files, and look after the file naming for you when you export.
Nyquist Macros have the benefit of being able to do things according to programmed logic.
In this case, we are splitting each file into 5 parts, so the Nyquist Macro will calculate the exact length of each part, then loop through the track, extracting successive parts at the calculated lengths.
This is the Nyquist code:
Code: Select all
;nyquist plug-in
;version 4
;type tool analyze
;name "Multi-split"
;author "Steve Daulton"
;release 2.3.2
;copyright "Released under terms of the GNU General Public License version 2"
(setf num 5) ; Number of parts to split into.
(setf dur (/ (get '*track* 'end-time) num))
(dotimes (i num)
(aud-do "SelectTracks: Track=0 TrackCount=1 Mode=Set")
(aud-do (format nil
"SelectTime:End=~a Start=~a"
(* i dur)
(* (1+ i) dur)))
(aud-do "Trim:")
(aud-do "Align_StartToZero:")
(aud-do "ExportWAV:")
(aud-do "Undo")
(aud-do "Undo"))
;; Return no-op.
""
To install the Nyquist macro, download the file here: then install the downloaded file as described here: https://manual.audacityteam.org/man/ins ... st_install
When installed and enabled, the plug-in will appear in the "Tools" menu, but we don't want to run it from there. Create a new (normal) Macro, and add the "Multi-split" plug-in to the Macro.
You can now run the normal Macro on the files, and it will apply the Nyquist Macro to each imported file in turn.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
-
billw58
- Forum Staff
- Posts: 5601
- Joined: Wed Aug 12, 2009 2:10 am
- Operating System: macOS 10.15 Catalina or later
Re: Batch split 35 separate 45 minute files into "3" 15 minute files each?
Steve: Aha! I didn't think of using Undo to get back to the state where the entire imported track is still there. Using that method one could string my macros together to extract the 5, 9-minute chunks.
-- Bill
-- Bill
-
billw58
- Forum Staff
- Posts: 5601
- Joined: Wed Aug 12, 2009 2:10 am
- Operating System: macOS 10.15 Catalina or later
Re: Batch split 35 separate 45 minute files into "3" 15 minute files each?
Here's a straight macro that will divide a file into 6, 9-minute chunks. Much faster than my first try, as this only has to import the original file once. Also, just select your 35 files (all in the same folder, right?) and walk away.
You can delete the sixth export (and the Undo, Undo, Select Time, Trim and Start-to-End steps) (steps 27 through 32) in the macro if you know your original files are exactly 45 minutes or less.
-- Bill
You can delete the sixth export (and the Undo, Undo, Select Time, Trim and Start-to-End steps) (steps 27 through 32) in the macro if you know your original files are exactly 45 minutes or less.
-- Bill
- Attachments
-
- 9-minute chunks.txt
- (456 Bytes) Downloaded 53 times
Re: Batch split 35 separate 45 minute files into "3" 15 minute files each?
Thanks much! I've been using the last one and it seems to work well for those 45-minute files. I'm also trying to reverse engineer (somewhat understanding) the Nyquist code.
So one question, if I needed to split the files up into "five-minute segments" and the folder of files I wanted to do that inside of had random files of unequal lengths (45 min, 90 min, 120 min etc), would the "9-minute chunks" macro be the best way to go about that? Could I just adjust the numbers (smaller segments) inside the macro to five minutes, then increaste the number of segments to always go to the 120 mark? What would happen if the file is shorter, would it just be wasted time? Thanks!
So one question, if I needed to split the files up into "five-minute segments" and the folder of files I wanted to do that inside of had random files of unequal lengths (45 min, 90 min, 120 min etc), would the "9-minute chunks" macro be the best way to go about that? Could I just adjust the numbers (smaller segments) inside the macro to five minutes, then increaste the number of segments to always go to the 120 mark? What would happen if the file is shorter, would it just be wasted time? Thanks!
Re: Batch split 35 separate 45 minute files into "3" 15 minute files each?
You could do that, but for the shorter tracks you will get a bunch of empty files when the track runs out of audio.bounzes wrote: ↑Wed Jun 12, 2019 6:55 pmif I needed to split the files up into "five-minute segments" and the folder of files I wanted to do that inside of had random files of unequal lengths (45 min, 90 min, 120 min etc), would the "9-minute chunks" macro be the best way to go about that? Could I just adjust the numbers (smaller segments) inside the macro to five minutes, then increaste the number of segments to always go to the 120 mark? What would happen if the file is shorter,
The "Nyquist Macro" has the advantage (because Nyquist is a programming language) that it can make the number of loops conditional on the length of the track. The plug-in that I posted previously could be modified quite easily to provide a general solution. A control could be added for the length that you want the sections to be, which you would then set when you add the plug-in to the Macro. If I have time later this evening, I'll see if I can knock together an example, and post it here.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: Batch split 35 separate 45 minute files into "3" 15 minute files each?
The line beginning ";control" tells Audacity to create a GUI with a "time" control (a new feature in Audacity 2.3.0) https://wiki.audacityteam.org/wiki/Nyqu ... ime_Widget
When calculating the number of segments, we need to round up "track length" / "segment length". I've done that by rounding down (truncate to integer), then checking if "num x dur" is less than the track length.
The double quotes at the end provide a valid "no-op" return value so that the macro is not interrupted.
"AUD-DO" is a Nyquist command that passes "Scripting command" (like the commands use in normal Macros) to Audacity (https://wiki.audacityteam.org/wiki/Nyqu ... o_Tutorial)
Code: Select all
;nyquist plug-in
;version 4
;type tool analyze
;name "Multi-split"
;author "Steve Daulton"
;release 2.3.2
;copyright "Released under terms of the GNU General Public License version 2"
;control dur "Maximum duration of files" time "" 300 1 14400
;Calculate number of segments
(setf num (truncate (/ (get '*track* 'end-time) dur)))
(when (< (* num dur) (get '*track* 'end-time))
(setf num (1+ num)))
(dotimes (i num)
(aud-do "SelectTracks: Track=0 TrackCount=1 Mode=Set")
(aud-do (format nil
"SelectTime:End=~a Start=~a"
(* i dur)
(* (1+ i) dur)))
(aud-do "Trim:")
(aud-do "Align_StartToZero:")
(aud-do "ExportWAV:")
(aud-do "Undo")
(aud-do "Undo"))
;; Return no-op.
""
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)