Spaces:
Running
on
T4
Running
on
T4
Update inference/style_transfer.py
Browse files- inference/style_transfer.py +18 -1
inference/style_transfer.py
CHANGED
@@ -21,6 +21,7 @@ currentdir = os.path.dirname(os.path.realpath(__file__))
|
|
21 |
sys.path.append(os.path.join(os.path.dirname(currentdir), "mixing_style_transfer"))
|
22 |
from networks import FXencoder, TCNModel
|
23 |
from data_loader import *
|
|
|
24 |
|
25 |
|
26 |
|
@@ -304,7 +305,23 @@ class Mixing_Style_Transfer_Inference:
|
|
304 |
return whole_batch_data
|
305 |
|
306 |
|
307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
os.environ['MASTER_ADDR'] = '127.0.0.1'
|
309 |
os.environ["CUDA_VISIBLE_DEVICES"] = '0'
|
310 |
os.environ['MASTER_PORT'] = '8888'
|
|
|
21 |
sys.path.append(os.path.join(os.path.dirname(currentdir), "mixing_style_transfer"))
|
22 |
from networks import FXencoder, TCNModel
|
23 |
from data_loader import *
|
24 |
+
import librosa
|
25 |
|
26 |
|
27 |
|
|
|
305 |
return whole_batch_data
|
306 |
|
307 |
|
308 |
+
|
309 |
+
def trim_audio(target_file_path, start_point_in_second=0, duration_in_second=30, sample_rate=44100):
|
310 |
+
# insure format
|
311 |
+
cur_aud, _ = librosa.load(target_file_path, sr=sample_rate, mono=False)
|
312 |
+
sf.write(target_file_path, cur_aud.transpose(-1, -2), sample_rate, 'PCM_16')
|
313 |
+
# trim if possible
|
314 |
+
cur_wav_length = load_wav_length(target_file_path)
|
315 |
+
if cur_wav_length < duration_in_second*sample_rate:
|
316 |
+
return
|
317 |
+
if cur_wav_length-start_point_in_second*sample_rate < duration_in_second*sample_rate:
|
318 |
+
trimmed_audio = load_wav_segment(target_file_path, start_point=start_point_in_second*sample_rate, axis=1)
|
319 |
+
else:
|
320 |
+
trimmed_audio = load_wav_segment(target_file_path, start_point=start_point_in_second*sample_rate, duration=duration_in_second*sample_rate, axis=1)
|
321 |
+
sf.write(target_file_path, trimmed_audio, sample_rate, 'PCM_16')
|
322 |
+
|
323 |
+
|
324 |
+
def set_up(start_point_in_second=0, duration_in_second=30):
|
325 |
os.environ['MASTER_ADDR'] = '127.0.0.1'
|
326 |
os.environ["CUDA_VISIBLE_DEVICES"] = '0'
|
327 |
os.environ['MASTER_PORT'] = '8888'
|