Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,10 +11,6 @@ from TTS.api import TTS
|
|
11 |
# # Set environment variables to accept license terms
|
12 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
# Глобальные переменные и настройки
|
19 |
language_options = {
|
20 |
"English (en)": "en",
|
@@ -48,22 +44,6 @@ other_language = {
|
|
48 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
|
49 |
|
50 |
# Функции для голосового клонирования
|
51 |
-
def clean_audio(audio_path):
|
52 |
-
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as temp_output:
|
53 |
-
out_filename = temp_output.name
|
54 |
-
|
55 |
-
lowpass_highpass = "lowpass=8000,highpass=75,"
|
56 |
-
trim_silence = "areverse,silenceremove=start_periods=1:start_silence=0:start_threshold=0.02,areverse,silenceremove=start_periods=1:start_silence=0:start_threshold=0.02,"
|
57 |
-
|
58 |
-
try:
|
59 |
-
shell_command = f"ffmpeg -y -i {audio_path} -af {lowpass_highpass}{trim_silence} {out_filename}".split()
|
60 |
-
subprocess.run(shell_command, capture_output=True, check=True)
|
61 |
-
print(f"Audio cleaned and saved to {out_filename}")
|
62 |
-
return out_filename
|
63 |
-
except subprocess.CalledProcessError as e:
|
64 |
-
print(f"Error during audio cleaning: {e}")
|
65 |
-
return audio_path
|
66 |
-
|
67 |
def check_audio_length(audio_path, max_duration=120):
|
68 |
try:
|
69 |
audio = AudioSegment.from_file(audio_path)
|
@@ -154,16 +134,10 @@ def process_speech(text, speaker_wav_path, selected_language, speed):
|
|
154 |
error = gr.Error(error_message, duration=5)
|
155 |
raise error
|
156 |
|
157 |
-
# Clean audio
|
158 |
-
cleaned_wav_path = clean_audio(speaker_wav_path)
|
159 |
-
|
160 |
if selected_language in other_language:
|
161 |
-
output_audio_data = synthesize_and_convert_voice(text, language_code,
|
162 |
else:
|
163 |
-
output_audio_data = synthesize_speech(text,
|
164 |
-
|
165 |
-
# Remove temporary files
|
166 |
-
os.remove(cleaned_wav_path)
|
167 |
|
168 |
return output_audio_data
|
169 |
|
|
|
11 |
# # Set environment variables to accept license terms
|
12 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
13 |
|
|
|
|
|
|
|
|
|
14 |
# Глобальные переменные и настройки
|
15 |
language_options = {
|
16 |
"English (en)": "en",
|
|
|
44 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
|
45 |
|
46 |
# Функции для голосового клонирования
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
def check_audio_length(audio_path, max_duration=120):
|
48 |
try:
|
49 |
audio = AudioSegment.from_file(audio_path)
|
|
|
134 |
error = gr.Error(error_message, duration=5)
|
135 |
raise error
|
136 |
|
|
|
|
|
|
|
137 |
if selected_language in other_language:
|
138 |
+
output_audio_data = synthesize_and_convert_voice(text, language_code, speaker_wav_path, speed)
|
139 |
else:
|
140 |
+
output_audio_data = synthesize_speech(text, speaker_wav_path, language_code, speed)
|
|
|
|
|
|
|
141 |
|
142 |
return output_audio_data
|
143 |
|