Spaces:
Runtime error
Runtime error
| !pip install "numpy<=1.26" # Install a NumPy version less than 1.27 | |
| !pip install "numba<0.59" # Install latest compatible Numba | |
| !pip install TTS | |
| # تثبيت المكتبات | |
| !pip install TTS pydub | |
| # استيراد الأدوات | |
| !pip uninstall -y numpy numba TTS pydub # Uninstall existing versions | |
| !pip install TTS pydub # Allow pip to install compatible versions | |
| !pip install gradio | |
| # استيراد الأدوات | |
| from TTS.api import TTS | |
| from pydub import AudioSegment | |
| from IPython.display import Audio | |
| import os | |
| from IPython.display import Audio, display | |
| import io | |
| import re | |
| import tempfile | |
| import gradio as gr | |
| from TTS.api import TTS | |
| import tempfile | |
| # تحميل النموذج الصوتي (تتعمل مرة واحدة عند أول تشغيل) | |
| tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False) | |
| # الدالة اللي هتشتغل لما المستخدم يكتب نص | |
| def text_to_speech(text): | |
| with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp: | |
| tts.tts_to_file(text=text, file_path=tmp.name) | |
| return tmp.name # Gradio بيقدر يشغل الملف الصوتي ده مباشرة | |
| # بناء واجهة Gradio | |
| iface = gr.Interface( | |
| fn=text_to_speech, | |
| inputs=gr.Textbox(lines=4, label="اكتب النص هنا"), | |
| outputs=gr.Audio(label="النتيجة"), | |
| title="🔊 تحويل النص لصوت - TTS", | |
| description="أكتب أي نص وسيتم تحويله إلى صوت باستخدام نموذج TTS من مكتبة Coqui." | |
| ) | |
| # تشغيل التطبيق محلياً أو على الإنترنت | |
| iface.launch(share=True) # share=True يعطيك لينك عام على الإنترنت | |