Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
import tempfile
|
|
|
|
| 2 |
import edge_tts
|
| 3 |
import gradio as gr
|
| 4 |
-
import asyncio
|
| 5 |
-
|
| 6 |
|
| 7 |
language_dict = {
|
| 8 |
"Hindi": {
|
|
@@ -442,58 +441,33 @@ language_dict = {
|
|
| 442 |
}
|
| 443 |
}
|
| 444 |
|
| 445 |
-
# Function to split text into manageable chunks
|
| 446 |
-
def split_text(text, max_length=200):
|
| 447 |
-
return [text[i:i + max_length] for i in range(0, len(text), max_length)]
|
| 448 |
-
|
| 449 |
-
# Async function to handle concurrent text-to-speech processing
|
| 450 |
-
async def process_chunk(chunk, voice):
|
| 451 |
-
communicate = edge_tts.Communicate(chunk, voice)
|
| 452 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 453 |
-
tmp_path = tmp_file.name
|
| 454 |
-
await communicate.save(tmp_path)
|
| 455 |
-
return tmp_path
|
| 456 |
|
| 457 |
-
# Main function to split and process text concurrently
|
| 458 |
async def text_to_speech_edge(text, language_code, speaker, tashkeel_checkbox=False):
|
| 459 |
-
|
| 460 |
-
voice = language_dict.get(language_code, {}).get(speaker)
|
| 461 |
-
if not voice:
|
| 462 |
-
return "Error: Selected language or speaker is not valid.", None
|
| 463 |
-
|
| 464 |
-
# Split text into chunks
|
| 465 |
-
text_chunks = split_text(text)
|
| 466 |
|
| 467 |
-
#
|
| 468 |
-
|
| 469 |
-
|
|
|
|
|
|
|
|
|
|
| 470 |
|
| 471 |
-
|
| 472 |
-
merged_audio_path = tempfile.mktemp(suffix=".mp3")
|
| 473 |
-
with open(merged_audio_path, "wb") as outfile:
|
| 474 |
-
for path in audio_paths:
|
| 475 |
-
with open(path, "rb") as infile:
|
| 476 |
-
outfile.write(infile.read())
|
| 477 |
|
| 478 |
-
return text, merged_audio_path
|
| 479 |
|
| 480 |
-
# update the lang box
|
| 481 |
def get_speakers(language):
|
| 482 |
print(language)
|
| 483 |
speakers = list(language_dict[language].keys())
|
| 484 |
return gr.Dropdown(choices=speakers, value=speakers[0], interactive=True), gr.Checkbox(visible=language == "Arabic", interactive=True)
|
| 485 |
|
| 486 |
-
|
| 487 |
-
# Default values
|
| 488 |
default_language = None
|
| 489 |
default_speaker = None
|
| 490 |
-
|
| 491 |
-
# Gradio UI setup
|
| 492 |
with gr.Blocks(title="Writoo AI V2") as demo:
|
| 493 |
gr.HTML(" ")
|
| 494 |
-
gr.HTML("<h2 style='color:Tomato;'> 🎥 **Exciting News: 60+ Minutes File Creation is also Free !!** 🎥 </
|
| 495 |
-
gr.Markdown("✨ Features: • Convert text to speech with 60+ audio files • Choose from 72+ languages • It's Free 😍")
|
| 496 |
|
|
|
|
| 497 |
with gr.Row():
|
| 498 |
with gr.Column():
|
| 499 |
input_text = gr.Textbox(lines=5, label="Input Text", placeholder="Enter text to convert to speech")
|
|
@@ -508,16 +482,8 @@ with gr.Blocks(title="Writoo AI V2") as demo:
|
|
| 508 |
output_text = gr.Textbox(label="Output Text")
|
| 509 |
output_audio = gr.Audio(type="filepath", label="Audio Output")
|
| 510 |
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
# Trigger text-to-speech function on button click
|
| 515 |
-
run_btn.click(
|
| 516 |
-
text_to_speech_edge,
|
| 517 |
-
inputs=[input_text, language, speaker, tashkeel_checkbox],
|
| 518 |
-
outputs=[output_text, output_audio]
|
| 519 |
-
)
|
| 520 |
|
| 521 |
-
# Launch the app
|
| 522 |
if __name__ == "__main__":
|
| 523 |
-
demo.queue().launch(share=False)
|
|
|
|
| 1 |
import tempfile
|
| 2 |
+
|
| 3 |
import edge_tts
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
| 5 |
|
| 6 |
language_dict = {
|
| 7 |
"Hindi": {
|
|
|
|
| 441 |
}
|
| 442 |
}
|
| 443 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
|
|
|
|
| 445 |
async def text_to_speech_edge(text, language_code, speaker, tashkeel_checkbox=False):
|
| 446 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
|
| 448 |
+
# Get the voice for the selected language and speaker
|
| 449 |
+
voice = language_dict[language_code][speaker]
|
| 450 |
+
communicate = edge_tts.Communicate(text, voice)
|
| 451 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 452 |
+
tmp_path = tmp_file.name
|
| 453 |
+
await communicate.save(tmp_path)
|
| 454 |
|
| 455 |
+
return text, tmp_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
|
|
|
|
| 457 |
|
|
|
|
| 458 |
def get_speakers(language):
|
| 459 |
print(language)
|
| 460 |
speakers = list(language_dict[language].keys())
|
| 461 |
return gr.Dropdown(choices=speakers, value=speakers[0], interactive=True), gr.Checkbox(visible=language == "Arabic", interactive=True)
|
| 462 |
|
| 463 |
+
|
|
|
|
| 464 |
default_language = None
|
| 465 |
default_speaker = None
|
|
|
|
|
|
|
| 466 |
with gr.Blocks(title="Writoo AI V2") as demo:
|
| 467 |
gr.HTML(" ")
|
| 468 |
+
gr.HTML(f"<h2 style='color:Tomato;'> 🎥 **Exciting News: 60+ Minutes File Creation is also Free !!** 🎥 </h3>")
|
|
|
|
| 469 |
|
| 470 |
+
gr.Markdown("✨ Features: • Convert text to speech with 60+ audio files.• Choose from 72+ languages • Its Free 😍")
|
| 471 |
with gr.Row():
|
| 472 |
with gr.Column():
|
| 473 |
input_text = gr.Textbox(lines=5, label="Input Text", placeholder="Enter text to convert to speech")
|
|
|
|
| 482 |
output_text = gr.Textbox(label="Output Text")
|
| 483 |
output_audio = gr.Audio(type="filepath", label="Audio Output")
|
| 484 |
|
| 485 |
+
language.change(get_speakers, inputs=[language], outputs=[speaker, tashkeel_checkbox])
|
| 486 |
+
run_btn.click(text_to_speech_edge, inputs=[input_text, language, speaker, tashkeel_checkbox], outputs=[output_text, output_audio])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 487 |
|
|
|
|
| 488 |
if __name__ == "__main__":
|
| 489 |
+
demo.queue().launch(share=False)
|