nomadkaraoke / python-audio-separator

Easy to use stem (e.g. instrumental/vocals) separation from CLI or as a python package, using a variety of amazing pre-trained models (primarily from UVR)
MIT License
428 stars 73 forks source link

Renaming files within `audio-separator` #128

Open Bebra777228 opened 3 days ago

Bebra777228 commented 3 days ago

I suggest improving the functionality of the audio-separator by adding two new parameters to the separate function: primary_name and secondary_name.

As a result, the code will look like this:

INPUT_PATH = "/content/input/music.mp3"
OUTPUT_PATH = "/content/output"
VOCALS = os.path.join(OUTPUT_PATH, "Vocals.wav")
INSTRUMENTAL = os.path.join(OUTPUT_PATH, "Instrumental.wav")

separator = Separator(output_dir=OUTPUT_PATH)
separator.load_model(model_filename="model_bs_roformer_ep_317_sdr_12.9755.ckpt")

voc_inst_result = separator.separate(INPUT_PATH, VOCALS, INSTRUMENTAL)

# or
voc_inst_result = separator.separate(INPUT_PATH, primary_name=VOCALS, secondary_name=INSTRUMENTAL)

If these parameters are not specified, the files will be output in the same way they are saved now.

This will be a more convenient option compared to the current approach, which requires additional file renaming:

INPUT_PATH = "/content/input/music.mp3"
OUTPUT_PATH = "/content/output"
VOCALS = os.path.join(OUTPUT_PATH, "Vocals.wav")
INSTRUMENTAL = os.path.join(OUTPUT_PATH, "Instrumental.wav")

separator = Separator(output_dir=OUTPUT_PATH)
separator.load_model(model_filename="model_bs_roformer_ep_317_sdr_12.9755.ckpt")

voc_inst_result = separator.separate(INPUT_PATH)
os.rename(os.path.join(output_dir, voc_inst_result[0]), INSTRUMENTAL)
os.rename(os.path.join(output_dir, voc_inst_result[1]), VOCALS)

Hope my idea is clear!

beveradb commented 3 days ago

Sure, fine by me if it doesn't break existing workflows - if you implement this in a PR, please add tests :)

Bebra777228 commented 3 days ago

I don't think I can do it, but I'll try :)