deezer / deezer/spleeter

[Discussion] How to export audio via API 'RAW waveform based separation'

Open
#872 0 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
28.4k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

I want to only save separated vocals into a specific directory, and I found 'File based separation' API cannot choose which part to save, so I decide use API **'RAW waveform based separation'**, I use `AudioSegment.export` to export the audio.
### Problem
But the exported audio sounds very piercing, it seems the audio quality is damaged. I don\`t know if my way to export audio is wrong🤔, please let me know if anyone have the same problem or you have any solution🙏🏻

main code below:
```python
from pydub import AudioSegment
from spleeter.separator import Separator
if __name__ == '__main__':
separator = Separator('spleeter:2stems')
sample_rate = 44100
audio_loader = AudioAdapter.default()
waveform, _ = audio_loader.load(audio_file_path)
# Perform the separation :
prediction = separator.separate(waveform)
# Save separated audio
vocals = AudioSegment(
prediction['vocals'].tobytes(),
frame_rate=sample_rate,
sample_width=prediction['vocals'].dtype.itemsize,
channels=2
)
vocals_output_path = os.path.join(output_directory, f'{filename}_vocals.wav')
vocals.export(vocals_output_path, format='wav')
```

But if I use 'File based separation' API, the exported audio sounds normal
```python
if __name__ == '__main__':
separator = Separator('spleeter:2stems')
output_directory = "output"
separator.separate_to_file(audio_file_path, output_directory)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.