0

I'm trying to use Spleeter to get a dictionary of the separate tracks (vocals, bass, etc.) from a wav file and the following is my code:

def seperator():
    separator = Separator('spleeter:4stems')
    file = "test.wav"
    audio_loader = AudioAdapter.default()
    sample_rate = 44100
    waveform, _ = audio_loader.load(file, sample_rate=sample_rate)
    prediction = separator._separate_librosa(waveform, file)
    print(prediction['vocals'])


def do_seperation():
    __name__ = '__main__'
    if __name__ == '__main__':
        seperator()

However, I get the following error message

RuntimeError: 
    An attempt has been made to start a new process before the
    current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

This seems to be a common error in Spleeter as I've gotten this error message before but have been able to resolve this by using if __name__ == '__main__': as a wrapper for my function but this time it isn't working. Is there any way to resolve this weird error? Any help appreciated, thanks!

wroex24
  • 33
  • 7
  • Writing `__name__ = '__main__'` makes the subsequent `if __name__ == '__main__':` test completely meaningless: you're forcing it to be true. – jasonharper Jun 23 '22 at 14:01
  • @jasonharper I see what you mean, and sorry I forgot to specify this but this code is in a class, so I can't really do `if __name__ == __main__` without making it actually true. – wroex24 Jun 23 '22 at 14:06
  • You can simply rely on the correct value of `__name__` that Python assigns for you. – jasonharper Jun 23 '22 at 14:09
  • @jasonharper Ahh okay that makes sense but I still get the same error – wroex24 Jun 23 '22 at 17:01
  • This is a workaround - just turn off multiprocessing as follows: ```separator = Separator('spleeter:4stems', multiprocess=False)``` – Neoheurist Jun 24 '22 at 15:22

0 Answers0