| | import os |
| | import torch |
| |
|
| | |
| | try: |
| | from TTS.tts.configs.xtts_config import XttsConfig |
| | torch.serialization.add_safe_globals([XttsConfig]) |
| | except ImportError: |
| | pass |
| |
|
| | |
| | os.environ["COQUI_TOS_AGREED"] = "1" |
| |
|
| | import gradio as gr |
| | from TTS.api import TTS |
| |
|
| | |
| | device = "cuda" if torch.cuda.is_available() else "cpu" |
| |
|
| | print("جاري تهيئة نموذج XTTS v2 العربي...") |
| | try: |
| | |
| | tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device) |
| | print("تم تحميل النموذج بنجاح!") |
| | except Exception as e: |
| | print(f"حدث خطأ أثناء تحميل النموذج: {e}") |
| |
|
| | def process_tts(text, audio_reference): |
| | if not text or not audio_reference: |
| | return None, "يرجى إدخال النص ورفع ملف صوتي مرجعي." |
| | |
| | output_file = "output_voice.wav" |
| | |
| | try: |
| | tts.tts_to_file( |
| | text=text, |
| | speaker_wav=audio_reference, |
| | language="ar", |
| | file_path=output_file |
| | ) |
| | return output_file, "تم توليد الصوت بنجاح!" |
| | except Exception as e: |
| | return None, f"خطأ أثناء التوليد: {str(e)}" |
| |
|
| | |
| | with gr.Blocks() as demo: |
| | gr.Markdown("# 🎙️ المحرك العربي النهائي لاستنساخ الصوت") |
| | |
| | with gr.Row(): |
| | with gr.Column(): |
| | txt_input = gr.Textbox(label="النص العربي", lines=5, placeholder="اكتب النص هنا...") |
| | audio_input = gr.Audio(label="عينة الصوت المرجعية", type="filepath") |
| | generate_btn = gr.Button("توليد الصوت الآن", variant="primary") |
| | |
| | with gr.Column(): |
| | audio_output = gr.Audio(label="الصوت الناتج") |
| | status_msg = gr.Textbox(label="حالة النظام", interactive=False) |
| |
|
| | generate_btn.click( |
| | fn=process_tts, |
| | inputs=[txt_input, audio_input], |
| | outputs=[audio_output, status_msg] |
| | ) |
| |
|
| | demo.launch() |
| |
|