huseinzol05 commited on
Commit
eb83dc0
·
1 Parent(s): 8d89471
Files changed (3) hide show
  1. README.md +3 -7
  2. app.py +91 -0
  3. requirements.txt +7 -0
README.md CHANGED
@@ -1,12 +1,8 @@
1
- ---
2
  title: Malay VITS
3
- emoji: 🐨
4
  colorFrom: pink
5
- colorTo: gray
6
  sdk: gradio
7
  sdk_version: 5.14.0
8
  app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  title: Malay VITS
2
+ emoji: 🗣️
3
  colorFrom: pink
4
+ colorTo: purple
5
  sdk: gradio
6
  sdk_version: 5.14.0
7
  app_file: app.py
8
+ pinned: false
 
 
 
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ os.environ['CUDA_VISIBLE_DEVICES'] = ''
4
+ os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
5
+
6
+ from huggingface_hub import snapshot_download
7
+ from malaya_speech.torch_model.vits.model_infer import SynthesizerTrn
8
+ from malaya_speech.torch_model.vits.commons import intersperse
9
+ from malaya_speech.utils.text import TTS_SYMBOLS
10
+ from malaya_speech.tts import load_text_ids
11
+ from malaya_speech.utils.astype import float_to_int
12
+ import gradio as gr
13
+ import torch
14
+ import os
15
+ import json
16
+
17
+ try:
18
+ from malaya_boilerplate.hparams import HParams
19
+ except BaseException:
20
+ from malaya_boilerplate.train.config import HParams
21
+
22
+ speaker_id = {
23
+ 'Husein': 0,
24
+ 'Shafiqah Idayu': 1,
25
+ }
26
+
27
+ normalizer = load_text_ids(pad_to = None, understand_punct = True, is_lower = False)
28
+
29
+ folder = snapshot_download(repo_id="malaysia-ai/malay-VITS-multispeaker")
30
+
31
+ with open(os.path.join(folder, 'config.json')) as fopen:
32
+ hps = HParams(**json.load(fopen))
33
+
34
+ model = SynthesizerTrn(
35
+ len(TTS_SYMBOLS),
36
+ hps.data.filter_length // 2 + 1,
37
+ hps.train.segment_size // hps.data.hop_length,
38
+ n_speakers=hps.data.n_speakers,
39
+ **hps.model,
40
+ ).eval()
41
+ model.load_state_dict(torch.load(os.path.join(folder, 'model.pth'), map_location='cpu'))
42
+
43
+
44
+ def tts(text, speaker, temperature, length_ratio):
45
+ if len(text) < 1:
46
+ raise gr.Error('input text must longer than 0')
47
+
48
+ if speaker not in speaker_id:
49
+ raise gr.Error('speaker is not available')
50
+
51
+ t, ids = normalizer.normalize(text, add_fullstop = True)
52
+ if hps.data.add_blank:
53
+ ids = intersperse(ids, 0)
54
+ ids = torch.LongTensor(ids)
55
+ ids_lengths = torch.LongTensor([ids.size(0)])
56
+ ids = ids.unsqueeze(0)
57
+ sid = torch.tensor([speaker_id[speaker]])
58
+
59
+ with torch.no_grad():
60
+ audio = model.infer(
61
+ ids,
62
+ ids_lengths,
63
+ noise_scale=0.0,
64
+ noise_scale_w=0.0,
65
+ length_scale=1.0,
66
+ sid=sid,
67
+ )
68
+ y_ = audio[0].numpy()
69
+
70
+ data = float_to_int(y_[0, 0])
71
+ return (22050, data)
72
+
73
+ demo = gr.Interface(
74
+ fn=tts,
75
+ inputs=[
76
+ gr.components.Textbox(label='Text'),
77
+ gr.components.Dropdown(label='Available speakers', choices=list(speaker_id.keys()), value = 'Husein'),
78
+ gr.Slider(0.0, 1.0, value=0.6666, label='temperature, changing this will manipulate pitch'),
79
+ gr.Slider(0.0, 3.0, value=1.0, label='length ratio, changing this will manipulate duration output'),
80
+ ],
81
+ outputs=['audio'],
82
+ examples=[
83
+ ['Syed Saddiq berkata, mereka seharusnya mengingati bahawa semasa menjadi Perdana Menteri Pakatan Harapan', 'Husein', 0.6666, 1.0],
84
+ ['Shah Alam - Pertubuhan Kebajikan Anak Bersatu Selangor bersetuju pihak kerajaan mewujudkan Suruhanjaya Siasatan Diraja untuk menyiasat isu kartel daging.', 'Shafiqah Idayu', 0.6666, 1.0],
85
+ ],
86
+ cache_examples=False,
87
+ title='End-to-End Malay TTS using VITS',
88
+ )
89
+
90
+ demo.queue().launch(server_name='0.0.0.0')
91
+
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ torch==2.5.1
2
+ torchaudio==2.5.1
3
+ malaya-speech @ git+https://github.com/mesolitica/malaya-speech
4
+ malaya
5
+ malaya-boilerplate
6
+ matplotlib
7
+ transformers