File size: 1,153 Bytes
bc5ef40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
import gradio as gr
import torchaudio

# تحميل النموذج مرة واحدة
models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
    "facebook/tts_transformer-ar-cv7",
    arg_overrides={"vocoder": "hifigan", "fp16": False}
)
model = models[0]
TTSHubInterface.update_cfg_with_data_cfg(cfg, task.data_cfg)
generator = task.build_generator(model, cfg)

def synthesize(text):
    sample = TTSHubInterface.get_model_input(task, text)
    wav, rate = TTSHubInterface.get_prediction(task, model, generator, sample)
    # حفظ الملف مؤقتًا
    path = "output.wav"
    torchaudio.save(path, wav.unsqueeze(0), rate)
    return path

interface = gr.Interface(
    fn=synthesize,
    inputs=gr.Textbox(label="أدخل نصاً باللغة العربية"),
    outputs=gr.Audio(label="الناتج الصوتي"),
    title="تحويل النص إلى صوت بالعربية",
    description="باستخدام النموذج: facebook/tts_transformer-ar-cv7"
)

interface.launch()