File size: 1,198 Bytes
8833400 af05ba7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
---
license: mit
datasets:
- kaist-audio-book
language:
- ko
pipeline_tag: text-to-speech
---
# SpeechT5 Text To Speech
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.
```py
import torch
from transformers import AutoTokenizer, SpeechT5HifiGan, SpeechT5ForTextToSpeech
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
tokenizer = AutoTokenizer.from_pretrained("Bingsu/speecht5_test")
model = SpeechT5ForTextToSpeech.from_pretrained("Bingsu/speecht5_test")
emb_url = "https://huggingface.co/Bingsu/speecht5_test/resolve/main/speaker_embedding.pt"
emb_sd = torch.hub.load_state_dict_from_url(emb_url, map_location="cpu")
emb = torch.nn.Embedding(model.config.num_speakers, model.config.speaker_embedding_dim)
emb.load_state_dict(emb_sd)
```
```py
@torch.inference_mode()
def gen(text: str, speaker_id: int = 0):
inputs = tokenizer(text, return_tensors="pt")
s_id = torch.tensor(speaker_id)
speaker_embeddings = emb(s_id).unsqueeze(0)
speech = model.generate_speech(inputs.input_ids, speaker_embeddings=speaker_embeddings, vocoder=vocoder)
return speech.numpy()
```
|