Being a fan of CLIs, I always wanted to create a command-line utility of my own. I was aiming for a practical application, instead of a tool which does nothing but print something on the console. And the result: aok

aok

aok is a command-line utility to split an audio file or join multiple audio files into one or do both. It is open source and can be accessed from github.

Installation

:: Warning :: Before you begin with installation, make sure that you have python 3.5+ installed on your system.

Dependencies

  • pydub: it makes audio processing task easier, plus it supports ffmpeg
  • Click: to manage the command-line interface of aok

:: Info :: I use and recommend pipenv to install and manage aok and its dependencies.

First, let’s clone the aok repository and change into it:

$ git clone https://github.com/thepoetdj/aok.git && cd aok

Assuming that you have pipenv installed on your system, create a virtual environment into the changed directory:

$ pipenv shell

Once the virtual environment is created and activated, install aok:

$ pipenv install -e .

Usage

Once installed, checkout the basic help message:

$ aok --help

Usage: aok [OPTIONS] COMMAND [ARGS]...

  A utility to split and/or join audio files.

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  join   Merge two or more audio files.
  split  Split a song for given number of seconds.

:: Warning :: aok is under active development, more commands will be added soon.

Merge audio files

Take a look at the help message of join command:

$ aok join --help

Usage: aok join [OPTIONS] INPUT...

  Merge two or more audio files.

Options:
  -f, --format [mp3|wav|aif|ogg]  The format of both input and output audio
  -o, --output PATH               Output file with absolute or relative path
  --help                          Show this message and exit.

With aok, you can merge multiple audio files into a single playlist. What’s more, you can also specify the audio format!

Let’s merge few audio files. aok supports mp3 extension by default.

$ aok join '100degrees.mp3' 'Dirty Disco.mp3' 'LA FIESTA.mp3'
Playlist created successfully!

Once you get the success message, checkout your current directory for the exported playlist.

The default output file has temporary name. If you want a specific name for your playlist, then use the -o/--output option:

$ aok join --output 'My Playlist.mp3' ...

As mentioned earlier, you can use aok on different audio formats:

$ aok join --format wav --output repeated_explosion.wav explosion.wav

:: Warning :: Both the input and output audio has to be of same format for the -f/--format option to work.

Did you notice that I gave only one audio as input? In such cases, the join command will simply repeat the audio in exported playlist. Cool, isn’t it?

Split an audio file

Let’s see what the split command does:

$ aok split --help

Usage: aok split [OPTIONS] INPUT

  Split a song for given number of seconds.

  The seconds are counted from the beginning of the input song. In case the
  number of seconds exceeds the input song's length, input song will be
  exported as it is.

Options:
  -f, --format [mp3|wav|aif|ogg]  The format of both input and output audio
  -s, --seconds INTEGER           The number of seconds to split the song for
                                  [required]
  -o, --output PATH               Output file with absolute or relative path
  --help                          Show this message and exit.

Say that you want only the first 25 seconds of a music file. With aok, you can do that as follows:

$ aok split -s 25 -o '25 seconds.mp3' 'My Music.mp3'

If everything goes right, you should see a success message. Also, in your working directory, an audio file with name 25 seconds.mp3 would be created that contains only the first 25 seconds of the input audio file.

Had you noticed the help message, you would already know that when the number of seconds provided exceeds the actual length of the input audio, it will be exported as it is. You will receive a warning message in such case though.

As mentioned previously, aok supports mp3 format by default. However, you can use one of the supported formats: mp3, wav, aif, ogg for your audio files. Just make sure to use the same format for audio files in that case.

The road ahead

I am actively looking for new ways to improve aok. Be it adding new feature, doing bugfixes, etc. Let me show you a glimpse of what I have lined up for future releases:

  • Export merge playlists with metadata information
  • Split files between start & end range
  • Add effects to an audio file
  • A way to execute both split and merge in a single command

With that said, see you again next time!