Update README.md
Browse files
README.md
CHANGED
@@ -13,4 +13,49 @@ datasets:
|
|
13 |
## Install TensorFlowTTS
|
14 |
```
|
15 |
pip install TensorFlowTTS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
```
|
|
|
13 |
## Install TensorFlowTTS
|
14 |
```
|
15 |
pip install TensorFlowTTS
|
16 |
+
```
|
17 |
+
### Converting your Text to Mel Spectrogram
|
18 |
+
```python
|
19 |
+
import numpy as np
|
20 |
+
import soundfile as sf
|
21 |
+
import yaml
|
22 |
+
import IPython.display as ipd
|
23 |
+
|
24 |
+
import tensorflow as tf
|
25 |
+
|
26 |
+
from tensorflow_tts.inference import AutoProcessor
|
27 |
+
from tensorflow_tts.inference import TFAutoModel
|
28 |
+
from tensorflow_tts.inference import AutoConfig
|
29 |
+
|
30 |
+
processor = AutoProcessor.from_pretrained(pretrained_path="./processor.json")
|
31 |
+
config = AutoConfig.from_pretrained("./config.yml")
|
32 |
+
fastspeech2 = TFAutoModel.from_pretrained(
|
33 |
+
config=config,
|
34 |
+
pretrained_path="./model.h5"
|
35 |
+
)
|
36 |
+
|
37 |
+
text = "xin chào đây là một ví dụ về chuyển đổi văn bản thành giọng nói"
|
38 |
+
|
39 |
+
input_ids = processor.text_to_sequence(text)
|
40 |
+
|
41 |
+
mel_before, mel_after, duration_outputs, _, _ = fastspeech2.inference(
|
42 |
+
input_ids=tf.expand_dims(tf.convert_to_tensor(input_ids, dtype=tf.int32), 0),
|
43 |
+
speaker_ids=tf.convert_to_tensor([0], dtype=tf.int32),
|
44 |
+
speed_ratios=tf.convert_to_tensor([1.0], dtype=tf.float32),
|
45 |
+
f0_ratios =tf.convert_to_tensor([1.0], dtype=tf.float32),
|
46 |
+
energy_ratios =tf.convert_to_tensor([1.0], dtype=tf.float32),
|
47 |
+
)
|
48 |
+
```
|
49 |
+
|
50 |
+
#### Bonus: Convert Mel Spectrogram to Speech
|
51 |
+
```python
|
52 |
+
mb_melgan = TFAutoModel.from_pretrained("tensorspeech/tts-mb_melgan-ljspeech-en")
|
53 |
+
|
54 |
+
audio_before = mb_melgan.inference(mel_before)[0, :, 0]
|
55 |
+
audio_after = mb_melgan.inference(mel_after)[0, :, 0]
|
56 |
+
|
57 |
+
sf.write("audio_before.wav", audio_before, 22050, "PCM_16")
|
58 |
+
sf.write("audio_after.wav", audio_after, 22050, "PCM_16")
|
59 |
+
|
60 |
+
ipd.Audio('audio_after.wav')
|
61 |
```
|