Spaces:
Sleeping
Sleeping
Aboubacar OUATTARA - kaira
commited on
Commit
•
175f658
1
Parent(s):
d2a76ad
add audios files
Browse files
app.py
CHANGED
@@ -61,52 +61,34 @@ def text_to_speech(bambara_text, reference_audio: Optional[Tuple] = None):
|
|
61 |
|
62 |
|
63 |
# Function to enhance speech
|
64 |
-
# @spaces.GPU
|
65 |
-
# def enhance_speech(audio_array, sampling_rate, solver, nfe, tau, denoise_before_enhancement):
|
66 |
-
# solver = solver.lower()
|
67 |
-
# nfe = int(nfe)
|
68 |
-
# lambd = 0.9 if denoise_before_enhancement else 0.1
|
69 |
-
#
|
70 |
-
# @spaces.GPU(duration=360)
|
71 |
-
# def denoise_audio():
|
72 |
-
# try:
|
73 |
-
# return denoise(audio_array, sampling_rate, device)
|
74 |
-
# except Exception as e:
|
75 |
-
# print("> Error while denoising : ", str(e))
|
76 |
-
# return audio_array, sampling_rate
|
77 |
-
#
|
78 |
-
# @spaces.GPU(duration=360)
|
79 |
-
# def enhance_audio():
|
80 |
-
# try:
|
81 |
-
# return enhance(audio_array, sampling_rate, device, nfe=nfe, solver=solver, lambd=lambd, tau=tau)
|
82 |
-
# except Exception as e:
|
83 |
-
# print("> Error while enhancement : ", str(e))
|
84 |
-
# return audio_array, sampling_rate
|
85 |
-
#
|
86 |
-
# with concurrent.futures.ThreadPoolExecutor() as executor:
|
87 |
-
# future_denoise = executor.submit(denoise_audio)
|
88 |
-
# future_enhance = executor.submit(enhance_audio)
|
89 |
-
#
|
90 |
-
# denoised_audio, new_sr1 = future_denoise.result()
|
91 |
-
# enhanced_audio, new_sr2 = future_enhance.result()
|
92 |
-
#
|
93 |
-
# # Convert to numpy and return
|
94 |
-
# return (new_sr1, denoised_audio.cpu().numpy()), (new_sr2, enhanced_audio.cpu().numpy())
|
95 |
-
|
96 |
def enhance_speech(audio_array, sampling_rate, solver, nfe, tau, denoise_before_enhancement):
|
97 |
solver = solver.lower()
|
98 |
nfe = int(nfe)
|
99 |
lambd = 0.9 if denoise_before_enhancement else 0.1
|
100 |
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
|
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
|
112 |
def resample_audio(audio_tensor, orig_sr, target_sr):
|
@@ -157,7 +139,7 @@ def _fn(
|
|
157 |
audio_array, sampling_rate = text_to_speech(bambara_text)
|
158 |
|
159 |
# Step 3: Enhance the audio
|
160 |
-
denoised_audio,
|
161 |
audio_array,
|
162 |
sampling_rate,
|
163 |
solver,
|
@@ -166,25 +148,12 @@ def _fn(
|
|
166 |
denoise_before_enhancement
|
167 |
)
|
168 |
|
169 |
-
denoised_audio_array = resample_audio(denoised_audio[1], denoised_audio[0], sampling_rate).numpy()
|
170 |
-
|
171 |
-
audio_out = audio_array.numpy()
|
172 |
-
print("audio_array sampling_rate", sampling_rate)
|
173 |
-
print("audio_array type", type(audio_out))
|
174 |
-
print("audio_array shape", audio_out.shape)
|
175 |
-
print("audio_array data", audio_out)
|
176 |
-
|
177 |
-
print("denoised_audio sampling_rate", sampling_rate)
|
178 |
-
print("denoised_audio type", type(denoised_audio_array))
|
179 |
-
print("denoised_audio shape", denoised_audio_array.shape)
|
180 |
-
print("denoised_audio data", denoised_audio_array)
|
181 |
-
|
182 |
# Return all outputs
|
183 |
return (
|
184 |
bambara_text,
|
185 |
(sampling_rate, audio_array.numpy()),
|
186 |
-
|
187 |
-
|
188 |
)
|
189 |
|
190 |
|
|
|
61 |
|
62 |
|
63 |
# Function to enhance speech
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
def enhance_speech(audio_array, sampling_rate, solver, nfe, tau, denoise_before_enhancement):
|
65 |
solver = solver.lower()
|
66 |
nfe = int(nfe)
|
67 |
lambd = 0.9 if denoise_before_enhancement else 0.1
|
68 |
|
69 |
+
def denoise_audio():
|
70 |
+
try:
|
71 |
+
return denoise(audio_array, sampling_rate, device)
|
72 |
+
except Exception as e:
|
73 |
+
print("> Error while denoising : ", str(e))
|
74 |
+
return audio_array, sampling_rate
|
75 |
|
76 |
+
def enhance_audio():
|
77 |
+
try:
|
78 |
+
return enhance(audio_array, sampling_rate, device, nfe=nfe, solver=solver, lambd=lambd, tau=tau)
|
79 |
+
except Exception as e:
|
80 |
+
print("> Error while enhancement : ", str(e))
|
81 |
+
return audio_array, sampling_rate
|
82 |
+
|
83 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
84 |
+
future_denoise = executor.submit(denoise_audio)
|
85 |
+
future_enhance = executor.submit(enhance_audio)
|
86 |
+
|
87 |
+
denoised_audio, new_sr1 = future_denoise.result()
|
88 |
+
enhanced_audio, new_sr2 = future_enhance.result()
|
89 |
+
|
90 |
+
# Convert to numpy and return
|
91 |
+
return (new_sr1, denoised_audio.cpu().numpy()), (new_sr2, enhanced_audio.cpu().numpy())
|
92 |
|
93 |
|
94 |
def resample_audio(audio_tensor, orig_sr, target_sr):
|
|
|
139 |
audio_array, sampling_rate = text_to_speech(bambara_text)
|
140 |
|
141 |
# Step 3: Enhance the audio
|
142 |
+
denoised_audio, enhanced_audio = enhance_speech(
|
143 |
audio_array,
|
144 |
sampling_rate,
|
145 |
solver,
|
|
|
148 |
denoise_before_enhancement
|
149 |
)
|
150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
# Return all outputs
|
152 |
return (
|
153 |
bambara_text,
|
154 |
(sampling_rate, audio_array.numpy()),
|
155 |
+
denoised_audio,
|
156 |
+
enhanced_audio
|
157 |
)
|
158 |
|
159 |
|