|
from spleeter.separator import Separator |
|
from spleeter.audio import adapter |
|
from pydub import AudioSegment |
|
import numpy as np |
|
import utils |
|
|
|
separator = None |
|
|
|
def seperate_ram(video): |
|
audio_loader = adapter.AudioAdapter.default() |
|
sample_rate = 44100 |
|
audio = video.audio |
|
|
|
|
|
arr = np.array(audio.get_array_of_samples()) |
|
audio, _ = audio_loader.load_waveform(arr) |
|
|
|
|
|
print("base audio\n", base_audio, "\n") |
|
|
|
|
|
|
|
def seperate_file(video, isolate_subs=True): |
|
global separator |
|
if not separator: |
|
separator = Separator('spleeter:2stems') |
|
source_audio_path = utils.get_output_path(video.file, '-audio.wav') |
|
isolated_path = utils.get_output_path(video.file, '-isolate.wav') |
|
separator.separate_to_file( |
|
(video.audio).export(source_audio_path, format="wav").name, |
|
'./output/', |
|
filename_format='{filename}-{instrument}.{codec}' |
|
) |
|
|
|
|
|
|
|
|
|
|
|
background_track = utils.get_output_path(source_audio_path, '-accompaniment.wav') |
|
|
|
if video.subs_removed: |
|
background = AudioSegment.from_file(background_track) |
|
for sub in video.subs_removed: |
|
background = background.overlay(video.get_snippet(sub.start, sub.end), int(sub.start*1000)) |
|
background.export(background_track, format="wav") |
|
video.background_track = background_track |
|
video.vocal_track = utils.get_output_path(isolated_path, '-vocals.wav') |
|
|