tts / app.py
m6011's picture
Update app.py
e9ef331 verified
raw
history blame contribute delete
No virus
989 Bytes
import os
# تشغيل setup.sh لتثبيت الحزم المطلوبة
os.system('bash setup.sh')
import gradio as gr
from espnet2.bin.tts_inference import Text2Speech
from transformers import AutoTokenizer, AutoModel
# تحميل SaudiBERT لتحليل النص
tokenizer = AutoTokenizer.from_pretrained("faisalq/SaudiBERT")
model = AutoModel.from_pretrained("faisalq/SaudiBERT")
# تحميل نموذج FastSpeech2
tts = Text2Speech.from_pretrained("kan-bayashi/fastspeech2")
# دالة لتحليل النص باستخدام SaudiBERT
def analyze_text(text):
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
return text
# دالة لتحويل النص إلى كلام
def tts_najdi(text):
processed_text = analyze_text(text)
speech = tts(processed_text)
return speech['wav']
# واجهة Gradio
iface = gr.Interface(fn=tts_najdi, inputs="text", outputs="audio", title="FastSpeech2 Najdi TTS Model with SaudiBERT")
iface.launch()