File size: 1,258 Bytes
c3cb969
 
99d4e63
c3cb969
99d4e63
c3cb969
 
99d4e63
c3cb969
 
 
99d4e63
c3cb969
 
 
99d4e63
c3cb969
 
 
 
 
 
 
 
 
 
 
 
 
99d4e63
 
 
c3cb969
 
 
99d4e63
 
c3cb969
99d4e63
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
34
35
36
37
38
39
40
# app.py

import gradio as gr
import torch
from espnet2.bin.tts_inference import Text2Speech
from espnet_model_zoo.downloader import ModelDownloader
from transformers import AutoTokenizer

# تحميل قائمة التوكينات
with open('tokens.txt', 'r', encoding='utf-8') as f:
    token_list = [line.strip() for line in f]

# تحميل النموذج المدرب
model_path = 'exp/tts_fastspeech2/train.total_count.ave_10best.pth'  # تأكد من مسار النموذج الصحيح
config_path = 'exp/tts_fastspeech2/config.yaml'

# إعداد Text2Speech
device = 'cuda' if torch.cuda.is_available() else 'cpu'
text2speech = Text2Speech.from_pretrained(
    model_file=model_path,
    config_file=config_path,
    device=device,
    threshold=0.5,
    maxlenratio=10.0,
    minlenratio=0.0,
    use_att_constraint=False,
    backward_window=1,
    forward_window=3,
)

# دالة لتحويل النص إلى كلام
def tts_najdi(text):
    with torch.no_grad():
        wav = text2speech(text)["wav"]
    return wav.view(-1).cpu().numpy(), 22050  # تأكد من استخدام معدل العينة الصحيح

# واجهة Gradio
iface = gr.Interface(fn=tts_najdi, inputs="text", outputs="audio", title="Najdi TTS Model")
iface.launch()