Granular Audio Musaicing Toolkit for Python
Project description
GAMuT: Granular Audio Musaicing Toolkit
Description
GAMuT is a high-level, user-friendly granular audio musaicing toolkit implemented in Python. Here are some examples of audio musaicing made with GAMuT:
- Target file: Ángel Gonzalez's "muerte en el olvido" excerpt
- Output: Female singer corpus
- Output: CMaj7 chord corpus
- Output: String instruments corpus
- Output: Tam tam corpus
- Output: Woodwind instruments corpus
Installation
To install gamut, simply run the pip install gamut command in the terminal.
Documentation
Broadly speaking, the audio musaicing pipeline with GAMuT is the following:
- build a corpus from one or more sound files.
- get an audio musaicing recipe from the corpus, given a target sound file.
- cook the audio musaicing recipe and write it into sound file.
To do this, a small collection of functions are included:
Main functions
-
build_corpus(): Takes a folder directory, or an audio file directory, or a list of directories to audio files, and returns adictobject (i.e. the corpus). The output can be saved as a.gamutfile with thedict_to_gamut()function, for later use inget_audio_recipe().- Required arguments:
input_dir(strorlist): Input audio file/folder directory, or list of audio file directories, from which to build a corpus.
- Optional arguments:
max_duration(int): maximum duration to analyze for all sound files ininput_dir. If set toNone, all sound files are analyzed in full. (Default: None)n_mfcc(int): number of MFCC bands. (Default: 13)hop_length(int): gap between subsequent frames, in samples. (Default: 512)frame_length(int): size of analysis window, in samples. (Default: 1024)kd(int): maximum number of MFCC bands to use for data query tree. If set toNone, a number is internally chosen based on the number of data samples.(Default: None)
- Returns (
dict): corpus dictionary object.
- Required arguments:
-
get_audio_recipe(): Takes an audio sample directory/path (i.e. the target) and adictobject (i.e. the corpus), and returns anotherdictobject containing the instructions to rebuild the target using grains from the corpus. The output can be saved as a.gamutfile with thedict_to_gamut()function, for later use incook_recipe().- Required arguments:
target_dir(str): directory of target sound file.corpus_dict(dict): dictionary object containing corpus.
- Optional arguments:
max_duration(int): maximum duration to analyze for target sound file. If set toNone, the sound file is analyzed in full.(Default: None)hop_length(int): gap between subsequent frames, in samples. (Default: 512)frame_length(int): size of analysis window, in samples. (Default: 1024)kn: number of best matches (KNN) to include in recipe. (Default: 8)
- Returns (
dict): target recipe dictionary object.
- Required arguments:
-
cook_recipe(): Takes adictobject (i.e. the recipe), and returns an array of audio samples, intended to be written as an audio file.- Required arguments:
recipe_dict(dict): directory object containing audio recipe.
- Optional arguments:
grain_dur(int,floatorlist): fixed value or envelope break points for grain duration, in seconds. (Default: 0.1)stretch_factor(int,floatorlist): fixed value or envelope break points for strech factor (i.e. speed). (Default: 1)onset_var(int,floatorlist): fixed value or envelope break points for grain onset variation, in seconds. (Default: 0)target_mix(int,floatorlist)*: fixed value or envelope break points for wet/dry mix, in the range of 0.0 to 1.0. (Default: 0)pan_depth(int,floatorlist): fixed value or envelope break points for panning depth (>= 0). (Default: 5)kn(int): maximum number of best matches to choose from for each grain. (Default: 8)n_chans(int): number of output channels. (Default: 2)envelope(strorlist): list of envelope break points, or string specifying window types. (Default: 'hann')sr(int): sampling rate of output. If set toNone, the target's sampling rate is used. (Default: None)frame_length_res(int): window size quantization unit. Larger windows increase efficiency at the expense of resolution in grain duration. (Default: 512)
- Returns (
ndarray): numpy array of audio samples.
- Required arguments:
Additionally, the following functions are included to read and write audio and .gamut[1] files:
dict_to_gamut(): writesdictobject into a.gamutfile. This function is a simple wrapper ofnumpy.save().- Required arguments:
dict(dict): dictionary containing corpus or recipe data.output_dir(str): output directory for.gamutfile.
- Returns (
NoneType): None
- Required arguments:
dict_from_gamut(): reads a.gamutfile as adictobject. This function is a simple wrapper ofnumpy.load().- Required arguments:
input_dir(str): input directory for.gamutfile.
- Returns (
dict): dictionary containing corpus or recipe data.
- Required arguments:
write_audio(): writes anndarrayas audio. This function is a simple wrapper ofsoundfile.write().- Required arguments:
output_dir(str): output directory of audio file. Output file format must be.wav,.aif, or.aiff.ndarray(ndarray): numpy array containing audio samples.
- Optional arguments:
sr(int): audio sampling rate of output file. (Default: 44100)bit_depth(int): audio bit rate of output file. (Default: 24)
- Returns (
NoneType): None
- Required arguments:
play_audio(): plays back anndarrayas audio. This function is a simple wrapper ofsounddevice.write().- Required arguments:
ndarray(ndarray): numpy array containing audio samples.
- Optional arguments:
sr(int): audio sampling rate. (Default: 44100)
- Returns (
NoneType): None
- Required arguments:
[1]: .gamut is a custom binary data format used for storing GAMuT corpora and recipe data. This file is simply a renaming of Numpy's .npy file extension.
Examples
- Basic: generates corpus, recipe, and audio in a single script — very slow, not recommended.
# imports
from gamut import gamut
# set target sound
target = './my_soundfile.wav'
# set corpus folder containing audio samples
audio_files = './my_audio_folder/'
# build corpus
corpus = gamut.build_corpus(input_dur=audio_files)
# make target recipe
recipe = gamut.get_audio_recipe(target_dir=target, corpus_dict=corpus)
# cook target recipe
audio_array = gamut.cook_recipe(recipe_dict=recipe)
# write output into audio file
gamut.write_audio(output_dir='./output.wav', ndarray=audio_array)
# plays back audio file
gamut.play_audio(ndarray=audio_array)
- Build corpus: Builds and writes
.gamutcorpus into file for future reuse.
# imports
from gamut import gamut
# set directory to audio folder
audio_files = './my_audio_folder/'
# build corpus from folder
my_corpus = gamut.build_corpus(input_dir=audio_files)
# set corpus output dir
output_dir = './my_corpus.gamut'
# write corpus into disk
gamut.dict_to_gamut(dict=my_corpus, output_dir=output_dir)
- Make recipe: Makes and writes
.gamutrecipe into file for future reuse.
# imports
from gamut import gamut
# directory of audio target
target_dir = './my_target_sound.wav'
# gamut corpus dir
corpus_dir = './my_corpus.gamut'
# load corpus
corpus = gamut.dict_from_gamut(input_dir=corpus_dir)
# build audio recipe
target_recipe = gamut.get_audio_recipe(target_dir=target_dir, corpus_dict=corpus)
# set recipe output dir
output_dir = './my_recipe.gamut'
# write recipe into disk
gamut.dict_to_gamut(dict=target_recipe, output_dir=output_dir)
- Cook recipe: Generates and writes audio file (
.wav,.aif. or.aif) from.gamutrecipe.
# imports
from gamut import gamut
# audio recipe dir
recipe_dir = './my_recipe.gamut'
# load corpus
recipe = gamut.dict_from_gamut(input_dir=recipe_dir)
# cooking settings
envelope = [0, 1, 0.5, 0.1, 0] # grain amplitude envelope (type: str, int, float or list -- if str, use scipy.signal.windows types)
grain_dur = [0.05, 0.25] # grain duration (type: int, float, or list)
sr = 44100 # output sampling rate (type: int)
pan_depth = [1, 40] # depth of panning across channels (>= 0) (type: int, float or list)
target_mix = [0, 0.5] # dry/wet mix of input target (0.0-1.0) (type: int, float, or list)
# cook audio recipe
audio_array = gamut.cook_recipe(recipe_dict=recipe,
grain_dur=grain_dur,
target_mix=target_mix,
pan_depth=pan_depth,
envelope=envelope,
sr=sr)
# set audio output dir
output_dir = './output.wav'
# write audio into disk
gamut.write_audio(output_dir=output_dir,
ndarray=audio_array,
sr=sr,
bit_depth=24)
# plays back audio file
gamut.play_audio(ndarray=audio_array)
License
ISC License Copyright (c) 2022, Felipe Tovar-Henao
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gamut-0.1.8.4.tar.gz.
File metadata
- Download URL: gamut-0.1.8.4.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
129f66f6a95ef622ceac1b4aa80605dc11d424a226e9d8fe7926206b10514777
|
|
| MD5 |
9467d96cc451870f093556408bd17344
|
|
| BLAKE2b-256 |
a939ebd0833d57f2d624638b8a4775fd67fae665c17d25ff603af9a27f21e419
|
File details
Details for the file gamut-0.1.8.4-py3-none-any.whl.
File metadata
- Download URL: gamut-0.1.8.4-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05b142e08c63fd4cee621a7c573fc82311bb3849300a041e7a92608fa6456980
|
|
| MD5 |
d6cbb3c02a2e02e3257c59b84cbdf694
|
|
| BLAKE2b-256 |
1ff03b7738157be4dc64fbb50f7fd5f0f565d4307cda58b5e7fe6d5daff74f4a
|