spleeter
spleeter copied to clipboard
[Bug]Python code for spleeter basics does not work
- [ 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)
- Installed using
pip
- Run as
...
- 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
Hi, did you managed to solve this issue? I'm getting the same problem on Windows 11
I'm getting the same problem on macOS
Same issue on win 10
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()
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!
Setting parameter "multiprocess" to False disables multiprocessing ability of separator
separator = Separator('spleeter:2stems', multiprocess = False)