Commit
Β·
16311fa
1
Parent(s):
fa758b4
Add subtitle generation option and guidance for SRT file creation in text_to_speech
Browse files
app.py
CHANGED
@@ -223,7 +223,8 @@ async def text_to_speech(text, voice, rate, pitch, generate_subtitles=False, upl
|
|
223 |
else:
|
224 |
# Use the existing approach for regular text
|
225 |
communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
|
226 |
-
|
|
|
227 |
if generate_subtitles:
|
228 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".srt") as srt_file:
|
229 |
subtitle_path = srt_file.name
|
@@ -336,7 +337,6 @@ async def create_demo():
|
|
336 |
with gr.Column(scale=3):
|
337 |
text_input = gr.Textbox(label="Input Text", lines=5, value="Hello, how are you doing!")
|
338 |
file_input = gr.File(label="Or upload a TXT/SRT file", file_types=[".txt", ".srt"])
|
339 |
-
|
340 |
with gr.Column(scale=2):
|
341 |
voice_dropdown = gr.Dropdown(
|
342 |
choices=[""] + list(voices.keys()),
|
@@ -354,6 +354,25 @@ async def create_demo():
|
|
354 |
minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1
|
355 |
)
|
356 |
subtitle_checkbox = gr.Checkbox(label="Generate Subtitles (.srt)", value=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
|
358 |
submit_btn = gr.Button("Convert to Speech", variant="primary")
|
359 |
warning_md = gr.Markdown(visible=False)
|
|
|
223 |
else:
|
224 |
# Use the existing approach for regular text
|
225 |
communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
|
226 |
+
if not generate_subtitles:
|
227 |
+
await communicate.save(audio_path)
|
228 |
if generate_subtitles:
|
229 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".srt") as srt_file:
|
230 |
subtitle_path = srt_file.name
|
|
|
337 |
with gr.Column(scale=3):
|
338 |
text_input = gr.Textbox(label="Input Text", lines=5, value="Hello, how are you doing!")
|
339 |
file_input = gr.File(label="Or upload a TXT/SRT file", file_types=[".txt", ".srt"])
|
|
|
340 |
with gr.Column(scale=2):
|
341 |
voice_dropdown = gr.Dropdown(
|
342 |
choices=[""] + list(voices.keys()),
|
|
|
354 |
minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1
|
355 |
)
|
356 |
subtitle_checkbox = gr.Checkbox(label="Generate Subtitles (.srt)", value=False)
|
357 |
+
gr.Markdown("""
|
358 |
+
**π Subtitle Timing Tip:**
|
359 |
+
|
360 |
+
When creating SRT files for continuous speech, avoid exact matching timestamps between segments.
|
361 |
+
|
362 |
+
**For smoother speech flow:**
|
363 |
+
```
|
364 |
+
1
|
365 |
+
00:00:00,112 --> 00:00:01,647
|
366 |
+
Hello how are you doing
|
367 |
+
|
368 |
+
2
|
369 |
+
00:00:01,617 --> 00:00:02,000
|
370 |
+
I'm fine
|
371 |
+
```
|
372 |
+
|
373 |
+
β
Create a small overlap (20-30ms) between segments to prevent pauses
|
374 |
+
β Avoid exact matching timestamps (where end time = next start time) except you want a pause
|
375 |
+
""")
|
376 |
|
377 |
submit_btn = gr.Button("Convert to Speech", variant="primary")
|
378 |
warning_md = gr.Markdown(visible=False)
|