spleeter icon indicating copy to clipboard operation
spleeter copied to clipboard

[Bug]Python code for spleeter basics does not work

Open gitinmathew opened this issue 2 years ago • 6 comments

  • [ Yes] I didn't find a similar issue already open.
  • [ Yes] I read the documentation (README AND Wiki)
  • [Yes ] I have installed FFMpeg
  • [Yes ] My problem is related to Spleeter only, not a derivative product (such as Webapplication, or GUI provided by others)

Description

Command line works but python code does NOT

Command line PS C:\Users...\Desktop> spleeter separate -p spleeter:2stems -o output .\ABCD.mp3 INFO:spleeter:File output\ABCD/accompaniment.wav written succesfully INFO:spleeter:File output\ABCD/vocals.wav written succesfully

Python code from spleeter.separator import Separator from spleeter.audio.adapter import AudioAdapter

separator = Separator('spleeter:2stems') audio_loader = AudioAdapter.default() sample_rate = 44100 waveform, _ = audio_loader.load('C:/Users/.../Desktop/.../ABCD.mp3', sample_rate=sample_rate)

prediction1 = separator.separate(waveform)

Step to reproduce

Python code from spleeter.separator import Separator from spleeter.audio.adapter import AudioAdapter

separator = Separator('spleeter:2stems') audio_loader = AudioAdapter.default() sample_rate = 44100 waveform, _ = audio_loader.load('C:/Users/.../Desktop/.../ABCD.mp3', sample_rate=sample_rate)

prediction1 = separator.separate(waveform)

  1. Installed using pip
  2. Run as ...
  3. Got ... error

Output

File "C:\Users...\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main raise RuntimeError(''' 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.

Environment

Windows 11 Pro

OS Windows
Installation type pip
RAM available XGo
Hardware spec GPU / CPU / etc ...

Additional context

gitinmathew avatar Jan 29 '23 00:01 gitinmathew

Hi, did you managed to solve this issue? I'm getting the same problem on Windows 11

vadd98 avatar Feb 26 '23 21:02 vadd98

I'm getting the same problem on macOS

119010291 avatar May 04 '23 14:05 119010291

Same issue on win 10

shuZro avatar Jun 02 '23 14:06 shuZro

This issue arises because of the way multiprocessing works for Python on Windows. You have to account for it manually, so here's a simple example with a separator:

from spleeter.separator import Separator
from multiprocessing import freeze_support

def main():
    # Your logic here, encapsulated in a function
    separator = Separator('spleeter:4stems')
    separator.separate_to_file('song.wav', 'audio/output')

if __name__ == '__main__':
    # Running your logic
    freeze_support()
    main()

perspektyvus avatar Aug 19 '23 19:08 perspektyvus

This issue arises because of the way multiprocessing works for Python on Windows. You have to account for it manually, so here's a simple example with a separator:

from spleeter.separator import Separator
from multiprocessing import freeze_support

def main():
    # Your logic here, encapsulated in a function
    separator = Separator('spleeter:4stems')
    separator.separate_to_file('song.wav', 'audio/output')

if __name__ == '__main__':
    # Running your logic
    freeze_support()
    main()

Thanks buddy that really fixed the problem!

InstaMinerAi avatar May 01 '24 04:05 InstaMinerAi

Setting parameter "multiprocess" to False disables multiprocessing ability of separator separator = Separator('spleeter:2stems', multiprocess = False)

Bill-XU avatar May 22 '24 02:05 Bill-XU