File size: 11,797 Bytes
e4436cf 6360a8e e4436cf a8a0472 57bb68d 6360a8e 5876f2a c8b4c8a 7a19353 5876f2a 7a19353 5876f2a 7a19353 c8b4c8a 7a19353 5876f2a 7a19353 5876f2a 7a19353 5876f2a 7a19353 5876f2a 2b2b1c5 5876f2a 6360a8e |
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
---
tags:
- transformers
- llama
- trl
- orpeheutts
- tts
- Texttospeech
license: apache-2.0
language:
- es
datasets:
- sirekist98/spanish_tts_noauddataset_24khz
base_model:
- canopylabs/3b-es_it-pretrain-research_release
pipeline_tag: text-to-speech
---
# Spanish TTS Model with Emotions and Multiple Voices
This repository contains a fine-tuned Spanish Text-to-Speech (TTS) model based on [`canopylabs/3b-es_it-pretrain-research_release`](https://huggingface.co/canopylabs/3b-es_it-pretrain-research_release). The model supports multiple voices and nuanced emotions, trained using [Unsloth](https://github.com/unslothai/unsloth) and [SNAC](https://huggingface.co/hubertsiuzdak/snac_24khz) for audio tokenization.
➡️ **Try it online**: [https://huggingface.co/spaces/sirekist98/orpheustts\_spanish\_tuned](https://huggingface.co/spaces/sirekist98/orpheustts_spanish_tuned)
---
## 👨💻 Model Summary
* **Base model**: `canopylabs/3b-es_it-pretrain-research_release`
* **Fine-tuned with**: LoRA adapters (64 rank, alpha 64)
* **Audio tokenization**: SNAC (24kHz)
* **Input format**: `source (emotion): text`
* **Dataset**: \~109k samples, 11 emotions × 11 speakers
* **Training framework**: Unsloth + Hugging Face Transformers
---
## 🚀 Training Overview
The model was trained on a curated subset of the dataset [`sirekist98/spanish_tts_noauddataset_24khz`](https://huggingface.co/datasets/sirekist98/spanish_tts_noauddataset_24khz). We selected combinations of speaker (`source`) and `emotion` with at least 1000 samples, resulting in a balanced dataset of over 109,000 examples.
Each sample was tokenized using SNAC and embedded in a prompt structured as:
```text
source (emotion): text
```
This prompt was then used to generate audio tokens, enabling the model to learn nuanced emotional prosody and voice control.
We trained the model for 1 epoch using gradient accumulation (batch size 8 × 4 steps) with 4-bit quantization on an NVIDIA L4 GPU.
---
## 🔊 Inference
You can run inference using the demo space: [Orpheus TTS Spanish Fine-Tuned](https://huggingface.co/spaces/sirekist98/orpheustts_spanish_tuned).
To run inference locally with full control:
```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
from snac import SNAC
# --- Minimal config ---
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
BASE = "canopylabs/3b-es_it-pretrain-research_release"
LORA = "sirekist98/spanish_tts_emotions"
SNAC_ID = "hubertsiuzdak/snac_24khz"
VOICE = "alloy"
EMOTION_ID = "intense_fear_dread_apprehension_horror_terror_panic"
TEXT = "Estoy atrapado, por favor ayúdame."
prompt = f"{VOICE} ({EMOTION_ID}): {TEXT}"
# --- Load models ---
tokenizer = AutoTokenizer.from_pretrained(BASE)
base_model = AutoModelForCausalLM.from_pretrained(
BASE,
torch_dtype=torch.float16 if device.type == "cuda" else torch.float32
)
model = PeftModel.from_pretrained(base_model, LORA).to(device).eval()
snac_model = SNAC.from_pretrained(SNAC_ID).to(device)
# --- Prepare input (same as your Space) ---
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
start_tok = torch.tensor([[128259]], dtype=torch.long).to(device)
end_toks = torch.tensor([[128009, 128260]], dtype=torch.long).to(device)
input_ids = torch.cat([start_tok, input_ids, end_toks], dim=1)
MAX_LEN = 4260
pad_len = MAX_LEN - input_ids.shape[1]
pad = torch.full((1, pad_len), 128263, dtype=torch.long).to(device)
input_ids = torch.cat([pad, input_ids], dim=1)
attention_mask = torch.cat(
[torch.zeros((1, pad_len), dtype=torch.long),
torch.ones((1, input_ids.shape[1] - pad_len), dtype=torch.long)],
dim=1
).to(device)
# --- Generate ---
generated = model.generate(
input_ids=input_ids,
attention_mask=attention_mask,
max_new_tokens=1200,
do_sample=True,
temperature=0.6,
top_p=0.95,
repetition_penalty=1.1,
num_return_sequences=1,
eos_token_id=128258,
use_cache=True
)
# --- Post-process (find 128257, remove 128258, multiple of 7, subtract 128266) ---
AUDIO_TOKEN_OFFSET = 128266
token_to_find = 128257
token_to_remove = 128258
idxs = (generated == token_to_find).nonzero(as_tuple=True)
cropped = generated[:, idxs[1][-1].item() + 1:] if len(idxs[1]) > 0 else generated
cleaned = cropped[cropped != token_to_remove]
codes = cleaned[: (len(cleaned) // 7) * 7].tolist()
codes = [int(t) - AUDIO_TOKEN_OFFSET for t in codes]
# --- SNAC decode (same layout as your Space) ---
layer_1, layer_2, layer_3 = [], [], []
for i in range((len(codes) + 1) // 7):
b = 7 * i
if b + 6 >= len(codes):
break
layer_1.append(codes[b + 0])
layer_2.append(codes[b + 1] - 4096)
layer_3.append(codes[b + 2] - 2 * 4096)
layer_3.append(codes[b + 3] - 3 * 4096)
layer_2.append(codes[b + 4] - 4 * 4096)
layer_3.append(codes[b + 5] - 5 * 4096)
layer_3.append(codes[b + 6] - 6 * 4096)
dev_snac = snac_model.quantizer.quantizers[0].codebook.weight.device
layers = [
torch.tensor(layer_1).unsqueeze(0).to(dev_snac),
torch.tensor(layer_2).unsqueeze(0).to(dev_snac),
torch.tensor(layer_3).unsqueeze(0).to(dev_snac),
]
with torch.no_grad():
audio = snac_model.decode(layers).squeeze().cpu().numpy()
# 'audio' is the 24kHz waveform.
# Optional:
# from scipy.io.wavfile import write as write_wav
# write_wav("output.wav", 24000, audio)
```
---
## 🗣️ Available Voices
You can generate speech using the following voices (`source`):
```
alloy, ash, ballad, coral, echo, fable, nova, onyx, sage, shimmer, verse
```
## 🌧️ Available Emotions for each voice
---
## alloy
* intense\_interest\_fascination\_curiosity\_and\_intrigue
* intense\_fear\_dread\_apprehension\_and\_horror
* intense\_ecstasy\_pleasure\_bliss\_rapture\_and\_beatitude
* intense\_numbness\_detachment\_insensitivity\_and\_apathy
* intense\_contempt\_disdain\_loathing\_and\_detestation
* intense\_astonishment\_surprise\_amazement\_and\_shock
* intense\_confusion\_bewilderment\_disorientation\_and\_perplexity
* intense\_pride\_dignity\_self\_confidence\_and\_honor
* intense\_sourness\_tartness\_and\_acidity
* intense\_sympathy\_compassion\_warmth\_trust\_and\_tenderness
## ash
* intense\_interest\_fascination\_curiosity\_and\_intrigue
* intense\_fear\_dread\_apprehension\_and\_horror
* intense\_ecstasy\_pleasure\_bliss\_rapture\_and\_beatitude
* intense\_numbness\_detachment\_insensitivity\_and\_apathy
* intense\_astonishment\_surprise\_amazement\_and\_shock
* intense\_sympathy\_compassion\_warmth\_trust\_and\_tenderness
## ballad
* intense\_interest\_fascination\_curiosity\_and\_intrigue
* intense\_fear\_dread\_apprehension\_and\_horror
* intense\_ecstasy\_pleasure\_bliss\_rapture\_and\_beatitude
* intense\_numbness\_detachment\_insensitivity\_and\_apathy
* intense\_contempt\_disdain\_loathing\_and\_detestation
* intense\_astonishment\_surprise\_amazement\_and\_shock
* intense\_confusion\_bewilderment\_disorientation\_and\_perplexity
* intense\_helplessness\_powerlessness\_desperation\_and\_submission
* intense\_pride\_dignity\_self\_confidence\_and\_honor
* intense\_sourness\_tartness\_and\_acidity
## coral
* intense\_fear\_dread\_apprehension\_and\_horror
* intense\_ecstasy\_pleasure\_bliss\_rapture\_and\_beatitude
* intense\_numbness\_detachment\_insensitivity\_and\_apathy
* intense\_contempt\_disdain\_loathing\_and\_detestation
* intense\_confusion\_bewilderment\_disorientation\_and\_perplexity
* intense\_helplessness\_powerlessness\_desperation\_and\_submission
* intense\_pride\_dignity\_self\_confidence\_and\_honor
* intense\_sourness\_tartness\_and\_acidity
* intense\_sympathy\_compassion\_warmth\_trust\_and\_tenderness
## echo
* intense\_interest\_fascination\_curiosity\_and\_intrigue
* intense\_ecstasy\_pleasure\_bliss\_rapture\_and\_beatitude
* intense\_numbness\_detachment\_insensitivity\_and\_apathy
* intense\_contempt\_disdain\_loathing\_and\_detestation
* intense\_astonishment\_surprise\_amazement\_and\_shock
* intense\_helplessness\_powerlessness\_desperation\_and\_submission
* intense\_pride\_dignity\_self\_confidence\_and\_honor
* intense\_sympathy\_compassion\_warmth\_trust\_and\_tenderness
## fable
* intense\_interest\_fascination\_curiosity\_and\_intrigue
* intense\_fear\_dread\_apprehension\_and\_horror
* intense\_ecstasy\_pleasure\_bliss\_rapture\_and\_beatitude
* intense\_numbness\_detachment\_insensitivity\_and\_apathy
* intense\_contempt\_disdain\_loathing\_and\_detestation
* intense\_helplessness\_powerlessness\_desperation\_and\_submission
* intense\_sourness\_tartness\_and\_acidity
## nova
* intense\_ecstasy\_pleasure\_bliss\_rapture\_and\_beatitude
* intense\_contempt\_disdain\_loathing\_and\_detestation
* intense\_astonishment\_surprise\_amazement\_and\_shock
* intense\_confusion\_bewilderment\_disorientation\_and\_perplexity
* intense\_helplessness\_powerlessness\_desperation\_and\_submission
* intense\_pride\_dignity\_self\_confidence\_and\_honor
* intense\_sourness\_tartness\_and\_acidity
* intense\_sympathy\_compassion\_warmth\_trust\_and\_tenderness
## onyx
* intense\_interest\_fascination\_curiosity\_and\_intrigue
* intense\_fear\_dread\_apprehension\_and\_horror
* intense\_numbness\_detachment\_insensitivity\_and\_apathy
* intense\_confusion\_bewilderment\_disorientation\_and\_perplexity
* intense\_helplessness\_powerlessness\_desperation\_and\_submission
* intense\_pride\_dignity\_self\_confidence\_and\_honor
* intense\_sympathy\_compassion\_warmth\_trust\_and\_tenderness
## sage
* intense\_interest\_fascination\_curiosity\_and\_intrigue
* intense\_fear\_dread\_apprehension\_and\_horror
* intense\_ecstasy\_pleasure\_bliss\_rapture\_and\_beatitude
* intense\_numbness\_detachment\_insensitivity\_and\_apathy
* intense\_astonishment\_surprise\_amazement\_and\_shock
* intense\_confusion\_bewilderment\_disorientation\_and\_perplexity
* intense\_pride\_dignity\_self\_confidence\_and\_honor
* intense\_sourness\_tartness\_and\_acidity
* intense\_sympathy\_compassion\_warmth\_trust\_and\_tenderness
## shimmer
* intense\_interest\_fascination\_curiosity\_and\_intrigue
* intense\_fear\_dread\_apprehension\_and\_horror
* intense\_ecstasy\_pleasure\_bliss\_rapture\_and\_beatitude
* intense\_numbness\_detachment\_insensitivity\_and\_apathy
* intense\_contempt\_disdain\_loathing\_and\_detestation
* intense\_astonishment\_surprise\_amazement\_and\_shock
* intense\_confusion\_bewilderment\_disorientation\_and\_perplexity
* intense\_helplessness\_powerlessness\_desperation\_and\_submission
* intense\_pride\_dignity\_self\_confidence\_and\_honor
* intense\_sourness\_tartness\_and\_acidity
## verse
* intense\_interest\_fascination\_curiosity\_and\_intrigue
* intense\_fear\_dread\_apprehension\_and\_horror
* intense\_ecstasy\_pleasure\_bliss\_rapture\_and\_beatitude
* intense\_numbness\_detachment\_insensitivity\_and\_apathy
* intense\_contempt\_disdain\_loathing\_and\_detestation
* intense\_astonishment\_surprise\_amazement\_and\_shock
* intense\_helplessness\_powerlessness\_desperation\_and\_submission
* intense\_sourness\_tartness\_and\_acidity
---
## 📖 Citation
```bibtex
@misc{sirekist2025spanishTTS,
author = {sirekist98},
title = {Spanish TTS Model with Emotions and Multiple Voices},
year = {2025},
howpublished = {\url{https://huggingface.co/sirekist98/spanish_model}}
}
```
---
## ✨ Acknowledgements
* [Unsloth](https://github.com/unslothai/unsloth)
* [SNAC](https://huggingface.co/hubertsiuzdak/snac_24khz)
* [Hugging Face Datasets and Spaces](https://huggingface.co/)
---
## ❓ Questions or Contributions?
Open an issue or contact [@sirekist98](https://huggingface.co/sirekist98) on Hugging Face.
Thanks for checking out this model! 🚀 |