-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpost_processing.py
More file actions
28 lines (25 loc) · 1.47 KB
/
post_processing.py
File metadata and controls
28 lines (25 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import librosa
import numpy as np
#import mathplotlib.pyplot as plt
import pickle
import torch
import os
import re
def reconstruct(phase, bass_mag, vocals_mag, drums_mag,others_mag,song_num,segment_num,destination_path):
# Retrieve complex STFT
vocals = np.squeeze(vocals_mag.detach().numpy() * phase,axis= (0,1))
#print(vocals.shape)
bass = np.squeeze(bass_mag.detach().numpy() * phase, axis=(0,1))
drums = np.squeeze(drums_mag.detach().numpy() * phase, axis=(0,1))
others = np.squeeze(others_mag.detach().numpy() * phase, axis=(0,1))
# Perform ISTFT
vocals_audio = librosa.istft(vocals, win_length=1024,hop_length=256,window='hann',center='True')
bass_audio = librosa.istft(bass, win_length=1024,hop_length=256,window='hann',center='True')
drums_audio = librosa.istft(drums, win_length=1024,hop_length=256,window='hann',center='True')
others_audio = librosa.istft(others, win_length=1024,hop_length=256,window='hann',center='True')
# Save as wav files
librosa.output.write_wav(os.path.join(destination_path,'vocals',str(song_num)+'_'+str(segment_num)+'.wav'), vocals_audio,sr=44100)
librosa.output.write_wav(os.path.join(destination_path,'bass',str(song_num)+'_'+str(segment_num)+'.wav'), bass_audio, sr=44100)
librosa.output.write_wav(os.path.join(destination_path,'drums',str(song_num)+'_'+str(segment_num)+'.wav'), drums_audio, sr=44100)
librosa.output.write_wav(os.path.join(destination_path,'others',str(song_num)+'_'+str(segment_num)+'.wav'), others_audio, sr=44100)
return