Changhan commited on
Commit
b0eeaa4
1 Parent(s): 525717b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -26
README.md CHANGED
@@ -9,40 +9,59 @@ language: en
9
  datasets:
10
  - ljspeech
11
  ---
12
- ## Example to download fastspeech2 from fairseq
13
 
14
- The following should work with fairseq's most up-to-date version in a google colab:
 
 
 
 
 
15
 
16
  ```python
17
  from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
 
18
  import IPython.display as ipd
19
- import torch
20
 
21
- model_ensemble, cfg, task = load_model_ensemble_and_task_from_hf_hub(
22
- "facebook/fastspeech2-en-ljspeech", arg_overrides={"vocoder": "griffin_lim", "fp16": False}
 
 
23
  )
 
 
 
24
 
25
- def tokenize(text):
26
- import g2p_en
27
- tokenized = g2p_en.G2p()(text)
28
- tokenized = [{",": "sp", ";": "sp"}.get(p, p) for p in tokenized]
29
- return " ".join(p for p in tokenized if p.isalnum())
30
-
31
  text = "Hello, this is a test run."
32
 
33
- tokenized = tokenize(text)
34
- sample = {
35
- "net_input": {
36
- "src_tokens": task.src_dict.encode_line(tokenized).view(1, -1),
37
- "src_lengths": torch.Tensor([len(tokenized.split())]).long(),
38
- "prev_output_tokens": None
39
- },
40
- "target_lengths": None,
41
- "speaker": None,
42
- }
43
- generator = task.build_generator(model_ensemble, cfg)
44
- generation = generator.generate(model_ensemble[0], sample)
45
- waveform = generation[0]["waveform"]
46
 
47
- ipd.Audio(waveform, rate=task.sr)
48
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  datasets:
10
  - ljspeech
11
  ---
12
+ # fastspeech2-en-ljspeech
13
 
14
+ [FastSpeech 2](https://arxiv.org/abs/2006.04558) text-to-speech model from [fairseq S^2](https://github.com/pytorch/fairseq/tree/main/examples/speech_synthesis):
15
+ - English
16
+ - Single-speaker female voice
17
+ - Trained on [LJSpeech](https://keithito.com/LJ-Speech-Dataset/)
18
+
19
+ ## Usage
20
 
21
  ```python
22
  from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
23
+ from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
24
  import IPython.display as ipd
 
25
 
26
+
27
+ models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
28
+ "facebook/fastspeech2-en-ljspeech",
29
+ arg_overrides={"vocoder": "hifigan", "fp16": False}
30
  )
31
+ model = models[0]
32
+ TTSHubInterface.update_cfg_with_data_cfg(cfg, task.data_cfg)
33
+ generator = task.build_generator(model, cfg)
34
 
 
 
 
 
 
 
35
  text = "Hello, this is a test run."
36
 
37
+ sample = TTSHubInterface.get_model_input(task, text)
38
+ wav, rate = TTSHubInterface.get_prediction(task, model, generator, sample)
39
+
40
+ ipd.Audio(wav, rate=rate)
41
+ ```
 
 
 
 
 
 
 
 
42
 
43
+ See also [fairseq S^2 example](https://github.com/pytorch/fairseq/blob/main/examples/speech_synthesis/docs/ljspeech_example.md).
44
+
45
+ ## Citation
46
+
47
+ ```bibtex
48
+ @inproceedings{wang-etal-2021-fairseq,
49
+ title = "fairseq S{\^{}}2: A Scalable and Integrable Speech Synthesis Toolkit",
50
+ author = "Wang, Changhan and
51
+ Hsu, Wei-Ning and
52
+ Adi, Yossi and
53
+ Polyak, Adam and
54
+ Lee, Ann and
55
+ Chen, Peng-Jen and
56
+ Gu, Jiatao and
57
+ Pino, Juan",
58
+ booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing: System Demonstrations",
59
+ month = nov,
60
+ year = "2021",
61
+ address = "Online and Punta Cana, Dominican Republic",
62
+ publisher = "Association for Computational Linguistics",
63
+ url = "https://aclanthology.org/2021.emnlp-demo.17",
64
+ doi = "10.18653/v1/2021.emnlp-demo.17",
65
+ pages = "143--152",
66
+ }
67
+ ```