Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wei-z-git opened this issue Oct 4, 2023 · 0 comments
Labels
question Further information is requested

Comments

@wei-z-git
Copy link

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:

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

if __name__ == '__main__':
    separator = Separator('spleeter:2stems')
    output_directory = "output" 
    separator.separate_to_file(audio_file_path, output_directory)
@wei-z-git wei-z-git added the question Further information is requested label Oct 4, 2023
@wei-z-git wei-z-git changed the title [Discussion] How to save audio via API 'RAW waveform based separation' [Discussion] How to export audio via API 'RAW waveform based separation' Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant