Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,11 +47,11 @@ def split_text_into_segments(text):
|
|
| 47 |
return segments
|
| 48 |
|
| 49 |
# Function to generate SRT with accurate timing per batch and cross-check timing
|
| 50 |
-
async def generate_accurate_srt(batch_text, batch_num, start_offset):
|
| 51 |
audio_file = f"batch_{batch_num}_audio.wav"
|
| 52 |
|
| 53 |
-
# Generate the audio using edge-tts
|
| 54 |
-
tts = edge_tts.Communicate(batch_text, "en-US-AndrewNeural", rate="-25%")
|
| 55 |
await tts.save(audio_file)
|
| 56 |
|
| 57 |
# Get the actual length of the audio file
|
|
@@ -81,7 +81,7 @@ async def generate_accurate_srt(batch_text, batch_num, start_offset):
|
|
| 81 |
return srt_content, audio_file, start_time # Return updated start time for cumulative tracking
|
| 82 |
|
| 83 |
# Batch processing function with cumulative timing, progress indicator, and final SRT validation
|
| 84 |
-
async def batch_process_srt_and_audio(script_text, progress=gr.Progress()):
|
| 85 |
batches = [script_text[i:i+500] for i in range(0, len(script_text), 500)]
|
| 86 |
all_srt_content = ""
|
| 87 |
combined_audio = AudioSegment.empty()
|
|
@@ -89,7 +89,7 @@ async def batch_process_srt_and_audio(script_text, progress=gr.Progress()):
|
|
| 89 |
|
| 90 |
# Process each batch sequentially to ensure proper timing and cumulative offset tracking
|
| 91 |
for batch_num, batch_text in enumerate(batches):
|
| 92 |
-
srt_content, audio_file, end_offset = await generate_accurate_srt(batch_text, batch_num, start_offset)
|
| 93 |
all_srt_content += srt_content
|
| 94 |
|
| 95 |
# Append the audio of each batch to the combined audio
|
|
@@ -129,20 +129,23 @@ async def batch_process_srt_and_audio(script_text, progress=gr.Progress()):
|
|
| 129 |
return final_srt_path, final_audio_path
|
| 130 |
|
| 131 |
# Gradio interface function
|
| 132 |
-
async def process_script(script_text):
|
| 133 |
-
srt_path, audio_path = await batch_process_srt_and_audio(script_text)
|
| 134 |
return srt_path, audio_path, audio_path
|
| 135 |
|
| 136 |
-
# Gradio interface setup
|
| 137 |
app = gr.Interface(
|
| 138 |
fn=process_script,
|
| 139 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
| 140 |
outputs=[
|
| 141 |
gr.File(label="Download SRT File"),
|
| 142 |
gr.File(label="Download Audio File"),
|
| 143 |
gr.Audio(label="Play Audio")
|
| 144 |
],
|
| 145 |
-
description="
|
| 146 |
)
|
| 147 |
|
| 148 |
app.launch()
|
|
|
|
| 47 |
return segments
|
| 48 |
|
| 49 |
# Function to generate SRT with accurate timing per batch and cross-check timing
|
| 50 |
+
async def generate_accurate_srt(batch_text, batch_num, start_offset, pitch):
|
| 51 |
audio_file = f"batch_{batch_num}_audio.wav"
|
| 52 |
|
| 53 |
+
# Generate the audio using edge-tts with pitch adjustment
|
| 54 |
+
tts = edge_tts.Communicate(batch_text, "en-US-AndrewNeural", rate="-25%", pitch=f"{pitch}Hz")
|
| 55 |
await tts.save(audio_file)
|
| 56 |
|
| 57 |
# Get the actual length of the audio file
|
|
|
|
| 81 |
return srt_content, audio_file, start_time # Return updated start time for cumulative tracking
|
| 82 |
|
| 83 |
# Batch processing function with cumulative timing, progress indicator, and final SRT validation
|
| 84 |
+
async def batch_process_srt_and_audio(script_text, pitch, progress=gr.Progress()):
|
| 85 |
batches = [script_text[i:i+500] for i in range(0, len(script_text), 500)]
|
| 86 |
all_srt_content = ""
|
| 87 |
combined_audio = AudioSegment.empty()
|
|
|
|
| 89 |
|
| 90 |
# Process each batch sequentially to ensure proper timing and cumulative offset tracking
|
| 91 |
for batch_num, batch_text in enumerate(batches):
|
| 92 |
+
srt_content, audio_file, end_offset = await generate_accurate_srt(batch_text, batch_num, start_offset, pitch)
|
| 93 |
all_srt_content += srt_content
|
| 94 |
|
| 95 |
# Append the audio of each batch to the combined audio
|
|
|
|
| 129 |
return final_srt_path, final_audio_path
|
| 130 |
|
| 131 |
# Gradio interface function
|
| 132 |
+
async def process_script(script_text, pitch):
|
| 133 |
+
srt_path, audio_path = await batch_process_srt_and_audio(script_text, pitch)
|
| 134 |
return srt_path, audio_path, audio_path
|
| 135 |
|
| 136 |
+
# Gradio interface setup with pitch adjustment slider
|
| 137 |
app = gr.Interface(
|
| 138 |
fn=process_script,
|
| 139 |
+
inputs=[
|
| 140 |
+
gr.Textbox(label="Enter Script Text", lines=10),
|
| 141 |
+
gr.Slider(label="Pitch Adjustment (Hz)", minimum=-100, maximum=100, step=1, value=0)
|
| 142 |
+
],
|
| 143 |
outputs=[
|
| 144 |
gr.File(label="Download SRT File"),
|
| 145 |
gr.File(label="Download Audio File"),
|
| 146 |
gr.Audio(label="Play Audio")
|
| 147 |
],
|
| 148 |
+
description="HIVEcorp TTS Generator with en-US-AndrewNeural voice (Rate: -25%) and an accurate SRT file for download."
|
| 149 |
)
|
| 150 |
|
| 151 |
app.launch()
|