Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +22 -30
- requirements.txt +1 -5
app.py
CHANGED
|
@@ -1,39 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
# تحميل نموذج
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
# دالة لتحويل النص إلى صوت
|
| 15 |
def text_to_speech(text):
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
# دمج المقاطع الصوتية معًا
|
| 27 |
-
final_output = "final_output.wav"
|
| 28 |
-
with open(final_output, 'wb') as f:
|
| 29 |
-
for audio_path in audio_paths:
|
| 30 |
-
with open(audio_path, 'rb') as audio_file:
|
| 31 |
-
f.write(audio_file.read())
|
| 32 |
-
os.remove(audio_path) # حذف الملفات المؤقتة بعد الدمج
|
| 33 |
-
|
| 34 |
-
return final_output
|
| 35 |
|
| 36 |
-
# واجهة المستخدم م
|
| 37 |
iface = gr.Interface(fn=text_to_speech, inputs="text", outputs="audio", live=True)
|
| 38 |
|
| 39 |
# تشغيل التطبيق
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torchaudio
|
| 3 |
+
from speechbrain.pretrained import FastSpeech2
|
| 4 |
+
from speechbrain.pretrained import HIFIGAN
|
| 5 |
|
| 6 |
+
# تحميل النموذج الصوتي
|
| 7 |
+
fastspeech2 = FastSpeech2.from_hparams(
|
| 8 |
+
source="speechbrain/tts-fastspeech2-ljspeech",
|
| 9 |
+
savedir="tmpdir_tts"
|
| 10 |
+
)
|
| 11 |
+
hifi_gan = HIFIGAN.from_hparams(
|
| 12 |
+
source="speechbrain/tts-hifigan-ljspeech",
|
| 13 |
+
savedir="tmpdir_vocoder"
|
| 14 |
+
)
|
| 15 |
|
| 16 |
# دالة لتحويل النص إلى صوت
|
| 17 |
def text_to_speech(text):
|
| 18 |
+
mel_output, durations, pitch, energy = fastspeech2.encode_text(
|
| 19 |
+
[text],
|
| 20 |
+
pace=1.0,
|
| 21 |
+
pitch_rate=1.0,
|
| 22 |
+
energy_rate=1.0
|
| 23 |
+
)
|
| 24 |
+
waveform = hifi_gan.decode_batch(mel_output)
|
| 25 |
+
torchaudio.save("output.wav", waveform.squeeze(1), 22050)
|
| 26 |
+
return "output.wav"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# واجهة المستخدم باستخدام Gradio
|
| 29 |
iface = gr.Interface(fn=text_to_speech, inputs="text", outputs="audio", live=True)
|
| 30 |
|
| 31 |
# تشغيل التطبيق
|
requirements.txt
CHANGED
|
@@ -1,8 +1,4 @@
|
|
| 1 |
-
TTS
|
| 2 |
-
numpy<=1.26
|
| 3 |
-
pydub
|
| 4 |
-
numba<0.59
|
| 5 |
speechbrain==0.5.12
|
| 6 |
gradio==3.10.0
|
| 7 |
torch==1.12.1
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
speechbrain==0.5.12
|
| 2 |
gradio==3.10.0
|
| 3 |
torch==1.12.1
|
| 4 |
+
torchaudio==0.12.1
|