A small tool to slice audio files into equal chunks


I wrote a quick little python script to allow you to take an audio file and splice it into Tidal-ready chunks in a destination directory. I wrote it this morning to take a whole directory of breaks and make them ready for tidal, after being inspired by kindohm's break tutorial here: https://www.youtube.com/watch?v=BzDy8r1Bjz8

You may find it of use, so I've posted it here: https://github.com/john-d-murphy/split_wave_file

lmk if it's of any use.



Very cool thank you~!
I'm totally new to Python but I'm pretty sure I've got it running okay in VSCode.

I assume that I need to change the "--source", --destination_directory, --prefix and --number_of_slices but I'm getting errors when I change those to the paths on my computer. Do I need to leave in the -- or format it in some specific way? And is there anything else that needs to be changed?

Sorry if this is basic Python but I'm brand new. Cheers.

In the function parse_argument you can see that each argument has a series of flags, e.g. -s and --source which represent short and long option.
They all are required=True therefore you have to insert them when you call the Python script.

When you call the script you have some options for declaring input args:
python split_wave_file.py -s "your-source"
python split_wave_file.py --source="your-source"
python split_wave_file.py --source "your-source"

1 Like

@ben sorry I didn't write a tutorial on this bc I wasn't sure exactly what problems people would run into.

@mattia.paterna thanks for clarifying!

Just to be clear, this is what the output should look like and here's some example runs.

Help output:

murphy@emergentprocess ~/tmp/code
$ ./split_wave_file.py -h
usage: split_wave_file.py [-h] -s SOURCE -d DESTINATION_DIRECTORY [-p PREFIX]
                      -n NUMBER_OF_SLICES

optional arguments:
 -h, --help            show this help message and exit
 -s SOURCE, --source SOURCE
                    Source Sound File (default: None)
                     Split Files Destination (default: None)
 -p PREFIX, --prefix PREFIX
                    Sliced File Prefix (default: None)
 -n NUMBER_OF_SLICES, --number_of_slices NUMBER_OF_SLICES
                    Number of Slices (default: None)

Example output with foo.wav into 2 slices:

murphy@emergentprocess ~/tmp/code
$ ./split_wave_file.py -s foo.wav -d ./bar -n 2
[2020-06-17 06:47:39,589] Source                 - foo.wav
[2020-06-17 06:47:39,589] Destination Directory  - ./bar
[2020-06-17 06:47:39,589] Number of Slices       - 2
[2020-06-17 06:47:39,589] Number of Frames       - 261333
[2020-06-17 06:47:39,589] Frames Per Slice       - 130666
[2020-06-17 06:47:39,589] Leftover Frames        - 1
[2020-06-17 06:47:39,589] Writing                - ./bar/foo_001.wav
[2020-06-17 06:47:39,589] Set Position           - 0
[2020-06-17 06:47:39,590] Writing                - ./bar/foo_002.wav
[2020-06-17 06:47:39,590] Set Position           - 130666 

Example output with the prefix specified:

murphy@emergentprocess ~/tmp/code
$ ./split_wave_file.py -s foo.wav -d ./bar -n 2 -p baz
[2020-06-17 06:49:05,443] Source                 - foo.wav
[2020-06-17 06:49:05,443] Destination Directory  - ./bar
[2020-06-17 06:49:05,443] Number of Slices       - 2
[2020-06-17 06:49:05,443] Prefix                 - baz
[2020-06-17 06:49:05,443] Number of Frames       - 261333
[2020-06-17 06:49:05,443] Frames Per Slice       - 130666
[2020-06-17 06:49:05,443] Leftover Frames        - 1
[2020-06-17 06:49:05,443] Writing                - ./bar/baz_001.wav
[2020-06-17 06:49:05,443] Set Position           - 0
[2020-06-17 06:49:05,444] Writing                - ./bar/baz_002.wav
[2020-06-17 06:49:05,444] Set Position           - 130666

Please let me know if you have any other questions - this is the first bit of code I've ever put into the public, so I don't know what people are looking for to help them get their head around my scripts.

Edit: I also uploaded the code so the default wave file name will be the file without its suffix. The code as of last night will do "foo.wav_001.wav" which works but is ugly.


Thanks all!
I think I'm getting hung up on setting the paths correctly.

Am I correct in assuming that the script is looking for the SOURCE audio file in the DESTINATION DIRECTORY?

So in your example code it's going to look for foo.wav in a folder called bar in your Home directly, yes?:

murphy@emergentprocess ~/tmp/code
$ ./split_wave_file.py -s foo.wav -d ./bar -n 2 -p baz

Thanks again.

In the example, it's looking for foo.wav in the local directory (expanding to /home/murphy/tmp/code/foo.wav) and will create the directory ./bar (expanding to /home/murphy/tmp/code/bar/) and put the resulting chopped samples in there.

Best to give it absolute paths if this is unclear.

1 Like

Ah... It will create the folder. I'll give it a go thanks.

I think I'm getting closer but I'm getting the following errors:

B-WYNN-MBP-2018:Python Rain$ /Users/Rain/Python/split_wave_file.py -s longVoxGrains.aif -d ./cut -n 2
[2020-06-17 11:44:07,077] Source                 - longVoxGrains.aif
[2020-06-17 11:44:07,077] Destination Directory  - ./cut
[2020-06-17 11:44:07,077] Number of Slices       - 2
Traceback (most recent call last):
  File "/Users/Rain/Python/split_wave_file.py", line 121, in <module>
  File "/Users/Rain/Python/split_wave_file.py", line 28, in main
    rfh = wave.open(arguments.source, mode="rb")
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wave.py", line 511, in open
    return Wave_read(f)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wave.py", line 164, in __init__
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wave.py", line 131, in initfp
    raise Error, 'file does not start with RIFF id'
wave.Error: file does not start with RIFF id

Let me know if these make any sense. Thanks again.

Ah! I'm using the wave file library in python - it apparently doesn't process aiffs.
You didn't do anything wrong.

I'll have to add https://docs.python.org/2/library/aifc.html support. Can you share the AIFF file you're trying to slice ? That way I can prove that it works and hand the code back to you.

Ahhh. That makes sense.

That file was quite long, but I made a trimmed version of it (and renamed it) here.
Let me know if that link doesn't work for some reason.


@ben Added AIFF support

Example session:


1 Like

That worked beautifully! And that video is super helpful.

Thanks for this!

1 Like

Great! I'm glad it worked.

1 Like