hivecorp commited on
Commit
4339ed2
·
verified ·
1 Parent(s): 1f02d0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -25
app.py CHANGED
@@ -442,24 +442,21 @@ language_dict = {
442
  }
443
 
444
 
445
- max_words = 1600 # Maximum word limit for input text
446
-
447
- async def generate_audio(text, language, voice):
448
- if len(text.split()) > max_words:
449
- return "Error: Input text exceeds the maximum allowed word limit of 1600.", None
450
 
451
- communicator = edge_tts.Communicate(text, voice)
 
 
 
452
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
453
- file_path = tmp_file.name
454
- await communicator.save(file_path)
455
- return None, file_path
456
-
457
-
458
- def tts_wrapper(text, language, voice):
459
- error_message, audio_path = gr.Blocks.run_coroutine(generate_audio(text, language, voice))
460
- if error_message:
461
- return error_message, None
462
- return None, audio_path
463
 
464
 
465
  def get_speakers(language):
@@ -468,8 +465,6 @@ def get_speakers(language):
468
  return gr.Dropdown(choices=speakers, value=speakers[0], interactive=True), gr.Checkbox(visible=language == "Arabic", interactive=True)
469
 
470
 
471
-
472
-
473
  default_language = None
474
  default_speaker = None
475
  with gr.Blocks(title="Writoo AI V2") as demo:
@@ -488,16 +483,11 @@ with gr.Blocks(title="Writoo AI V2") as demo:
488
  run_btn = gr.Button(value="Generate Audio", variant="primary")
489
 
490
  with gr.Column():
491
- error_output = gr.Textbox(label="Error Message", interactive=False)
492
  output_audio = gr.Audio(type="filepath", label="Audio Output")
493
 
494
-
495
  language.change(get_speakers, inputs=[language], outputs=[speaker, tashkeel_checkbox])
496
- run_btn.click(tts_wrapper, inputs=[input_text, language, speaker], outputs=[error_output, output_audio])
497
 
498
  if __name__ == "__main__":
499
  demo.queue().launch(share=False)
500
-
501
-
502
-
503
-
 
442
  }
443
 
444
 
445
+ async def generate_tts(text, language_code, speaker, tashkeel_checkbox=False):
446
+ char_limit = 10000 # Define the character limit
447
+ if len(text) > char_limit:
448
+ return f"Error: The input text exceeds the character limit of {char_limit} characters."
 
449
 
450
+ # Proceed with the existing logic
451
+ try:
452
+ voice = language_dict[language_code][speaker]
453
+ communicate = edge_tts.Communicate(text, voice)
454
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
455
+ tmp_path = tmp_file.name
456
+ await communicate.save(tmp_path)
457
+ return text, tmp_path
458
+ except Exception as e:
459
+ return f"Error: {str(e)}"
 
 
 
 
 
460
 
461
 
462
  def get_speakers(language):
 
465
  return gr.Dropdown(choices=speakers, value=speakers[0], interactive=True), gr.Checkbox(visible=language == "Arabic", interactive=True)
466
 
467
 
 
 
468
  default_language = None
469
  default_speaker = None
470
  with gr.Blocks(title="Writoo AI V2") as demo:
 
483
  run_btn = gr.Button(value="Generate Audio", variant="primary")
484
 
485
  with gr.Column():
486
+ output_text = gr.Textbox(label="Output Text")
487
  output_audio = gr.Audio(type="filepath", label="Audio Output")
488
 
 
489
  language.change(get_speakers, inputs=[language], outputs=[speaker, tashkeel_checkbox])
490
+ run_btn.click(text_to_speech_edge, inputs=[input_text, language, speaker, tashkeel_checkbox], outputs=[output_text, output_audio])
491
 
492
  if __name__ == "__main__":
493
  demo.queue().launch(share=False)