AJ | Pact | logo
PACT
Prism Fission

Prism Fission

9 September 2017

CreativePact (32 posts)

In this CreativePact, following a couple of months in the creative doldrums, I will be working to complete Prism Exhilarated, a unique media music release by ‑otron.

Prism in Python - unpacking audio

15/09/17
AJ Pact | Prism Fission | Prism in Python - unpacking audio

I pushed forward with pydub and the audio side of the Python script today by creating a routine to unpack audio assets, depending on whether the user has selected to play a track or the whole album.

First on the list was to actually get access to the files. For that I used the Path object of the pathlib module to set the project folder path, then used path settings from album.yaml to fill in the remaining path to the necessary assets.

pydub's AudioSegment objects require a path string, and creating a string from a Path object is as simple as casting the object with str(). With that in place, I defined the unpack_audio function, which takes an optional track index – calling with no argument unpacks audio for the whole album - and returns that audio. (Right now it only returns the backing track audio.)

I'm now in position to create the routine to construct the album, right now though just from the backing tracks.