Text-to-Speech
Fairseq
English
audio
patrickvonplaten commited on
Commit
afe8005
1 Parent(s): 17530a7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +33 -6
README.md CHANGED
@@ -1,12 +1,39 @@
1
  ## Example to download fastspeech2 from fairseq
2
 
3
- Weights are downloaded from:
4
-
5
- We still need to git clone this repo first before being able to download it.
6
- Having `cd`'ed into the repo we can do the following:
7
 
8
  ```python
9
  from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf
10
 
11
- model = load_model_ensemble_and_task_from_hf("patrickvonplaten/fairseq-fastspeech2")
12
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ## Example to download fastspeech2 from fairseq
2
 
3
+ The following should work with fairseq's most up-to-date version in a google colab:
 
 
 
4
 
5
  ```python
6
  from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf
7
 
8
+ model_ensemble, cfg, task = load_model_ensemble_and_task_from_hf_hub(
9
+ "facebook/fastspeech2-test", arg_overrides={"vocoder": "griffin_lim", "fp16": False}
10
+ )
11
+
12
+ def tokenize(text):
13
+ import g2p_en
14
+ tokenized = g2p_en.G2p()(text)
15
+ tokenized = [{",": "sp", ";": "sp"}.get(p, p) for p in tokenized]
16
+ return " ".join(p for p in tokenized if p.isalnum())
17
+
18
+ text = "This is a cool demo for speech synthesis, don't you think so?"
19
+
20
+ tokenized = tokenize(text)
21
+ sample = {
22
+ "net_input": {
23
+ "src_tokens": task.src_dict.encode_line(tokenized).view(1, -1),
24
+ "src_lengths": torch.Tensor([len(tokenized.split())]).long(),
25
+ "prev_output_tokens": None
26
+ },
27
+ "target_lengths": None,
28
+ "speaker": None,
29
+ }
30
+ generator = task.build_generator(model_ensemble, cfg)
31
+ generation = generator.generate(model_ensemble[0], sample)
32
+ waveform = generation[0]["waveform"]
33
+
34
+ import IPython.display as ipd
35
+
36
+ ipd.Audio(waveform, rate=task.sr)
37
+ ```
38
+
39
+ See: https://colab.research.google.com/drive/1gvq4Y1urrg9QrQ9031sZIP93LKspIh_X?usp=sharing