Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
mrfakename
commited on
Commit
•
60b0d11
1
Parent(s):
011f2d2
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,10 @@ import os
|
|
14 |
import tempfile
|
15 |
from pydub import AudioSegment
|
16 |
|
|
|
|
|
|
|
|
|
17 |
# from gradio_space_ci import enable_space_ci
|
18 |
|
19 |
# enable_space_ci()
|
@@ -573,6 +577,11 @@ def synthandreturn(text):
|
|
573 |
try:
|
574 |
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
|
575 |
audio = AudioSegment.from_file(result)
|
|
|
|
|
|
|
|
|
|
|
576 |
audio.export(f.name, format="wav")
|
577 |
os.unlink(result)
|
578 |
result = f.name
|
|
|
14 |
import tempfile
|
15 |
from pydub import AudioSegment
|
16 |
|
17 |
+
def match_target_amplitude(sound, target_dBFS):
|
18 |
+
change_in_dBFS = target_dBFS - sound.dBFS
|
19 |
+
return sound.apply_gain(change_in_dBFS)
|
20 |
+
|
21 |
# from gradio_space_ci import enable_space_ci
|
22 |
|
23 |
# enable_space_ci()
|
|
|
577 |
try:
|
578 |
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
|
579 |
audio = AudioSegment.from_file(result)
|
580 |
+
try:
|
581 |
+
print('Trying to normalize audio')
|
582 |
+
audio = match_target_amplitude(audio, -20)
|
583 |
+
except:
|
584 |
+
print('[WARN] Unable to normalize audio')
|
585 |
audio.export(f.name, format="wav")
|
586 |
os.unlink(result)
|
587 |
result = f.name
|