Skip to content

Instantly share code, notes, and snippets.

@Denperidge
Last active June 26, 2020 22:15
Show Gist options
  • Save Denperidge/674badb78998b78bc7106dffb06b7522 to your computer and use it in GitHub Desktop.
Save Denperidge/674badb78998b78bc7106dffb06b7522 to your computer and use it in GitHub Desktop.
A simple cli that will run spleeter without too much hassle

Spleeter-Bash

Simply run spleeter-bash.sh "/path/to/file" "/path/to/file/x/if/multiple/", select the model you'd like to use, and done! The script will make sure the pretrained_models are saved with spleeter-bash.sh (so they don't need to be redownloaded every run) and will make sure that the output gets set in a subdirectory of the source file. (In case of multiple files, the first files' directory will be used, since Spleeter only supports one output directory)

Prerequisites

# Select model
model_selected=false
while [ $model_selected = false ]; do
echo "The following models are available:"
echo "[1] - vocals / accompaniment (2 stems)"
echo "[2] - vocals / bass / drums / other (4 stems)"
echo "[3] - vocals / bass / drums / piano / other (5 stems)"
read -p "Select a model: " model
if [ $model = "1" ] || [ $model = "[1]" ]; then
model_selected=true
model="spleeter:2stems"
output_dirname="2stems"
elif [ $model = "2" ] || [ $model = "[2]" ]; then
model_selected=true
model="spleeter:4stems"
output_dirname="4stems"
elif [ $model = "3" ] || [ $model = "[3]" ]; then
model_selected=true
model="spleeter:5stems"
output_dirname="5stems"
fi
done
# Activate conda env
source ~/anaconda3/etc/profile.d/conda.sh
conda activate base
# Aggregate all files to be processed
files=()
for file in "$@"
do
files+=("$file")
done
cd "$(dirname $0)"
# Use first arguments dir for output
output_dir="$(dirname "$1")/output-$output_dirname"
py -3.7 -m spleeter separate -i "${files[@]}" -o "$output_dir" -p $model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment