Amir20255 commited on
Commit
2ef489c
·
verified ·
1 Parent(s): 23541bd

Upload 2 files

Browse files
Files changed (2) hide show
  1. TTS.py +42 -0
  2. requirements.txt +2 -0
TTS.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install "numpy<=1.26" # Install a NumPy version less than 1.27
2
+ !pip install "numba<0.59" # Install latest compatible Numba
3
+ !pip install TTS
4
+ # تثبيت المكتبات
5
+ !pip install TTS pydub
6
+ # استيراد الأدوات
7
+ !pip uninstall -y numpy numba TTS pydub # Uninstall existing versions
8
+ !pip install TTS pydub # Allow pip to install compatible versions
9
+ !pip install gradio
10
+ # استيراد الأدوات
11
+ from TTS.api import TTS
12
+ from pydub import AudioSegment
13
+ from IPython.display import Audio
14
+ import os
15
+ from IPython.display import Audio, display
16
+ import io
17
+ import re
18
+ import tempfile
19
+ import gradio as gr
20
+ from TTS.api import TTS
21
+ import tempfile
22
+
23
+ # تحميل النموذج الصوتي (تتعمل مرة واحدة عند أول تشغيل)
24
+ tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False)
25
+
26
+ # الدالة اللي هتشتغل لما المستخدم يكتب نص
27
+ def text_to_speech(text):
28
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
29
+ tts.tts_to_file(text=text, file_path=tmp.name)
30
+ return tmp.name # Gradio بيقدر يشغل الملف الصوتي ده مباشرة
31
+
32
+ # بناء واجهة Gradio
33
+ iface = gr.Interface(
34
+ fn=text_to_speech,
35
+ inputs=gr.Textbox(lines=4, label="اكتب النص هنا"),
36
+ outputs=gr.Audio(label="النتيجة"),
37
+ title="🔊 تحويل النص لصوت - TTS",
38
+ description="أكتب أي نص وسيتم تحويله إلى صوت باستخدام نموذج TTS من مكتبة Coqui."
39
+ )
40
+
41
+ # تشغيل التطبيق محلياً أو على الإنترنت
42
+ iface.launch(share=True) # share=True يعطيك لينك عام على الإنترنت
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ TTS
2
+ gradio