Update README.md
Browse files
README.md
CHANGED
@@ -9,4 +9,30 @@ pipeline_tag: text-to-speech
|
|
9 |
|
10 |
# SpeechT5 Text To Speech
|
11 |
|
12 |
-
DON'T USE THIS. This is a model that failed to train. However, someone saw my code and asked me to share this model, so I put it up.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# SpeechT5 Text To Speech
|
11 |
|
12 |
+
DON'T USE THIS. This is a model that failed to train. However, someone saw my code and asked me to share this model, so I put it up.
|
13 |
+
|
14 |
+
|
15 |
+
```py
|
16 |
+
import torch
|
17 |
+
from transformers import AutoTokenizer, SpeechT5HifiGan, SpeechT5ForTextToSpeech
|
18 |
+
|
19 |
+
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained("Bingsu/speecht5_test")
|
21 |
+
model = SpeechT5ForTextToSpeech.from_pretrained("Bingsu/speecht5_test")
|
22 |
+
|
23 |
+
emb_url = "https://huggingface.co/Bingsu/speecht5_test/resolve/main/speaker_embedding.pt"
|
24 |
+
emb_sd = torch.hub.load_state_dict_from_url(emb_url, map_location="cpu")
|
25 |
+
emb = torch.nn.Embedding(model.config.num_speakers, model.config.speaker_embedding_dim)
|
26 |
+
emb.load_state_dict(emb_sd)
|
27 |
+
```
|
28 |
+
|
29 |
+
```py
|
30 |
+
@torch.inference_mode()
|
31 |
+
def gen(text: str, speaker_id: int = 0):
|
32 |
+
inputs = tokenizer(text, return_tensors="pt")
|
33 |
+
s_id = torch.tensor(speaker_id)
|
34 |
+
|
35 |
+
speaker_embeddings = emb(s_id).unsqueeze(0)
|
36 |
+
speech = model.generate_speech(inputs.input_ids, speaker_embeddings=speaker_embeddings, vocoder=vocoder)
|
37 |
+
return speech.numpy()
|
38 |
+
```
|