File size: 978 Bytes
5c5bc25
f4a1d9e
 
 
5c5bc25
f4a1d9e
 
 
 
 
 
 
 
 
5c5bc25
 
 
f4a1d9e
 
 
 
 
 
 
 
 
5c5bc25
f4a1d9e
5c5bc25
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gradio as gr
import torchaudio
from speechbrain.pretrained import FastSpeech2
from speechbrain.pretrained import HIFIGAN

# تحميل النموذج الصوتي
fastspeech2 = FastSpeech2.from_hparams(
    source="speechbrain/tts-fastspeech2-ljspeech",
    savedir="tmpdir_tts"
)
hifi_gan = HIFIGAN.from_hparams(
    source="speechbrain/tts-hifigan-ljspeech",
    savedir="tmpdir_vocoder"
)

# دالة لتحويل النص إلى صوت
def text_to_speech(text):
    mel_output, durations, pitch, energy = fastspeech2.encode_text(
        [text],
        pace=1.0,
        pitch_rate=1.0,
        energy_rate=1.0
    )
    waveform = hifi_gan.decode_batch(mel_output)
    torchaudio.save("output.wav", waveform.squeeze(1), 22050)
    return "output.wav"

# واجهة المستخدم باستخدام Gradio
iface = gr.Interface(fn=text_to_speech, inputs="text", outputs="audio", live=True)

# تشغيل التطبيق
iface.launch()