Spaces:
Runtime error
Runtime error
| 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() | |