Update app.py
Browse files
app.py
CHANGED
|
@@ -29,7 +29,7 @@ def get_audio_length(audio_file):
|
|
| 29 |
|
| 30 |
def format_time_ms(milliseconds):
|
| 31 |
seconds, ms = divmod(int(milliseconds), 1000)
|
| 32 |
-
mins, secs = divmod(
|
| 33 |
hrs, mins = divmod(mins, 60)
|
| 34 |
return f"{hrs:02}:{mins:02}:{secs:02},{ms:03}"
|
| 35 |
|
|
@@ -465,7 +465,8 @@ async def process_text_with_progress(
|
|
| 465 |
):
|
| 466 |
# Input validation
|
| 467 |
if not text or text.strip() == "":
|
| 468 |
-
|
|
|
|
| 469 |
|
| 470 |
# Format pitch and rate strings
|
| 471 |
pitch_str = f"{pitch:+d}Hz" if pitch != 0 else "+0Hz"
|
|
@@ -490,13 +491,14 @@ async def process_text_with_progress(
|
|
| 490 |
)
|
| 491 |
|
| 492 |
# If successful, return results and hide error
|
| 493 |
-
|
|
|
|
| 494 |
except TTSError as e:
|
| 495 |
-
# Return specific TTS error
|
| 496 |
-
return None, None, None,
|
| 497 |
except Exception as e:
|
| 498 |
-
# Return any other error
|
| 499 |
-
return None, None, None,
|
| 500 |
|
| 501 |
# Voice options dictionary
|
| 502 |
voice_options = {
|
|
@@ -640,7 +642,7 @@ with gr.Blocks(title="Advanced TTS with Configurable SRT Generation") as app:
|
|
| 640 |
srt_file,
|
| 641 |
audio_file,
|
| 642 |
audio_output,
|
| 643 |
-
error_output,
|
| 644 |
download_link # Ensure download_link is updated with the new HTML for download
|
| 645 |
],
|
| 646 |
api_name="generate"
|
|
|
|
| 29 |
|
| 30 |
def format_time_ms(milliseconds):
|
| 31 |
seconds, ms = divmod(int(milliseconds), 1000)
|
| 32 |
+
mins, secs = divmod(mins, 60)
|
| 33 |
hrs, mins = divmod(mins, 60)
|
| 34 |
return f"{hrs:02}:{mins:02}:{secs:02},{ms:03}"
|
| 35 |
|
|
|
|
| 465 |
):
|
| 466 |
# Input validation
|
| 467 |
if not text or text.strip() == "":
|
| 468 |
+
# Return gr.update to control visibility and value of error_output
|
| 469 |
+
return None, None, None, gr.update(value="Please enter some text to convert to speech.", visible=True), None
|
| 470 |
|
| 471 |
# Format pitch and rate strings
|
| 472 |
pitch_str = f"{pitch:+d}Hz" if pitch != 0 else "+0Hz"
|
|
|
|
| 491 |
)
|
| 492 |
|
| 493 |
# If successful, return results and hide error
|
| 494 |
+
# Return gr.update(visible=False) to hide the error_output
|
| 495 |
+
return srt_path, audio_path, audio_path, gr.update(value="", visible=False), create_download_link(audio_path)
|
| 496 |
except TTSError as e:
|
| 497 |
+
# Return specific TTS error and make error_output visible
|
| 498 |
+
return None, None, None, gr.update(value=f"TTS Error: {str(e)}", visible=True), None
|
| 499 |
except Exception as e:
|
| 500 |
+
# Return any other error and make error_output visible
|
| 501 |
+
return None, None, None, gr.update(value=f"Unexpected error: {str(e)}", visible=True), None
|
| 502 |
|
| 503 |
# Voice options dictionary
|
| 504 |
voice_options = {
|
|
|
|
| 642 |
srt_file,
|
| 643 |
audio_file,
|
| 644 |
audio_output,
|
| 645 |
+
error_output, # Now expects a gr.update object for visibility and value
|
| 646 |
download_link # Ensure download_link is updated with the new HTML for download
|
| 647 |
],
|
| 648 |
api_name="generate"
|