whooray commited on
Commit
59c83aa
·
verified ·
1 Parent(s): 08ab5e3

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import librosa
4
+ import soundfile as sf
5
+
6
+
7
+ def inference(audio_1, audio_2):
8
+ # Load the audio files
9
+ translated_audio, sr_tr = librosa.load(audio_1, sr=None)
10
+ background_audio, sr_bg = librosa.load(audio_2, sr=None)
11
+
12
+ # Ensure both audio files have the same sample rate
13
+ if sr_bg != sr_tr:
14
+ translated_audio = librosa.resample(translated_audio, sr_tr, sr_bg)
15
+ sr = sr_bg
16
+ else:
17
+ sr = sr_bg # or sr_tr, they're the same
18
+
19
+ # Pad or truncate the audio to make them the same length
20
+ max_len = max(len(background_audio), len(translated_audio))
21
+ background_audio = librosa.util.fix_length(background_audio, max_len)
22
+ translated_audio = librosa.util.fix_length(translated_audio, max_len)
23
+
24
+ # Mix the audio
25
+ full_audio = background_audio + translated_audio
26
+
27
+ # Normalize to prevent clipping
28
+ full_audio = librosa.util.normalize(full_audio)
29
+
30
+ # Write the output
31
+ return full_audio
32
+
33
+ title = "음성 합성"
34
+
35
+ gr.Interface(
36
+ inference,
37
+ [gr.Audio(type="filepath", label="Vocals"),gr.Audio(type="filepath", label="배경음")],
38
+ gr.Audio(type="numpy", label="합성 결과"),
39
+ title=title,
40
+ ).launch(enable_queue=True, debug=True)