Created
October 18, 2020 18:42
-
-
Save ypujante/a212b39c5df78b27f0a54830f5c243dc to your computer and use it in GitHub Desktop.
python 3 script to extract vocals from a song using the Docker researchdeezer/spleeter image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Example: | |
# > cd /tmp | |
# extract_vocals.py '/Users/ypujante/Music/iTunes/iTunes Music/Music/Janet Jackson/Janet/08 This Time.m4a' | |
# Generates /tmp/08 This Time/vocals.wav and /tmp/08 This Time/accompaniment.wav | |
import argparse | |
import os | |
import subprocess | |
spleeter_docker_image = "researchdeezer/spleeter:3.7-2stems" | |
parser = argparse.ArgumentParser(usage='extract_vocals.py [-h] [-o output] <input>') | |
parser.add_argument("-n", "--dry-run", help="Dry run (prints what it is going to do)", action="store_true", dest="dry_run") | |
parser.add_argument("-v", "--verbose", help="Verbose", action="store_true") | |
parser.add_argument("-o", "--output", help="Output directory (default to current dir)") | |
parser.add_argument("input", help="Input file to extract vocals from") | |
args = parser.parse_args() | |
input = os.path.realpath(args.input) | |
output = os.path.realpath(args.output if args.output else os.getcwd()) | |
dir, filename = os.path.split(input) | |
verbose = [] if not args.verbose else ['--verbose'] | |
cmd = [ | |
'docker', 'run', | |
'-v', f'{dir}:/input', | |
'-v', f'{output}:/output', | |
spleeter_docker_image, | |
'separate', *verbose, '-i', f'/input/{filename}', '-o', '/output' | |
] | |
if args.dry_run: | |
print(' '.join(cmd)) | |
else: | |
subprocess.run(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works on macOS but you need to make sure that the Docker VM image has enough memory. If you see this kind of warnings:
you should increase the size of the memory allocated to the VM