Amir20255 commited on
Commit
5c5bc25
·
verified ·
1 Parent(s): 78b7e84

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +33 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from TTS.api import TTS
3
+ import re
4
+
5
+ # تحميل نموذج صوتي عربي أو إنجليزي
6
+ tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=True)
7
+
8
+ # دالة لتحويل النص إلى جمل صغيرة بحيث لا تتجاوز 50 كلمة
9
+ def split_text_into_chunks(text, max_words=50):
10
+ words = text.split()
11
+ chunks = [words[i:i + max_words] for i in range(0, len(words), max_words)]
12
+ return [" ".join(chunk) for chunk in chunks]
13
+
14
+ # دالة لتحويل النص إلى صوت
15
+ def text_to_speech(text):
16
+ # تقسيم النص إلى جمل أو مقاطع
17
+ chunks = split_text_into_chunks(text)
18
+
19
+ # توليد الصوت لكل جزء
20
+ audio_paths = []
21
+ for i, chunk in enumerate(chunks):
22
+ output_file = f"output_{i}.wav"
23
+ tts.tts_to_file(text=chunk, file_path=output_file)
24
+ audio_paths.append(output_file)
25
+
26
+ # دمج المقاطع الصوتية معًا
27
+ return audio_paths
28
+
29
+ # واجهة المستخدم مع Gradio
30
+ iface = gr.Interface(fn=text_to_speech, inputs="text", outputs="audio", live=True)
31
+
32
+ # تشغيل التطبيق
33
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ TTS
2
+ gradio
3
+ numpy<=1.26
4
+ pydub
5
+ numba<0.59