Views
No views yet
1
2import torch
3import numpy as np
4import soundfile as sf
5from IPython.display import Audio as IPythonAudio
6from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Processor
7
8# ── Load model ──────────────────────────────────────────────────────────────
9model_id = "DanishMahdi/speecht5_finetuned_sindhi_digits"
10processor = SpeechT5Processor.from_pretrained(model_id)
11model = SpeechT5ForTextToSpeech.from_pretrained(model_id)
12vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
13
14# ── Speaker embedding ───────────────────────────────────────────────────────
15# speaker_mean_embeddings: dict of {speaker_id: 512-dim numpy array}
16# obtained by averaging x-vectors across all utterances of each speaker
17target_speaker = list(speaker_mean_embeddings.keys())[0]
18speaker_emb = torch.tensor(
19 np.array(speaker_mean_embeddings[target_speaker], dtype=np.float32)
20).unsqueeze(0) # shape: (1, 512)
21
22# ── Normalize Sindhi script
23text = normalize_text("ھڪ") # (1)
24print(f"Input: 'ھڪ' → normalized: '{text}'")
25
26# ── Generate speech ─────────────────────────────────────────────────────────
27inputs = processor(text=text, return_tensors="pt")
28speech = model.generate_speech(inputs["input_ids"], speaker_emb, vocoder=vocoder)
29
30display(IPythonAudio(speech.numpy(), rate=16000))
31sf.write("output.wav", speech.numpy(), samplerate=16000)| Training Loss | Epoch | Step | Validation Loss |
|---|---|---|---|
| 1.6538 | 1.0929 | 200 | 0.8015 |
| 1.4826 | 2.1858 | 400 | 0.7021 |
| 1.3317 | 3.2787 | 600 | 0.6665 |
| 1.2469 | 4.3716 | 800 | 0.6149 |
| 1.2163 | 5.4645 | 1000 | 0.6035 |
| 1.1473 | 6.5574 | 1200 | 0.5750 |
| 1.1213 | 7.6503 | 1400 | 0.5863 |
| 1.1055 | 8.7432 | 1600 | 0.5584 |
| 1.0704 | 9.8361 | 1800 | 0.5591 |
| 1.0603 | 10.9290 | 2000 | 0.5491 |
1@inproceedings{ao-etal-2022-speecht5,
2 title = {SpeechT5: Unified-Modal Encoder-Decoder Pre-Training for Spoken Language Processing},
3 author = {Ao, Junyi and Wang, Rui and Zhou, Long and others},
4 booktitle = {Proceedings of ACL 2022},
5 year = {2022}
6}
7
8@misc{mahdi-2026-sindhi-digits-tts,
9 title = {SpeechT5 Fine-tuned for Sindhi Spoken Digit Synthesis},
10 author = {Danish Mahdi},
11 year = {2026},
12 publisher = {Hugging Face},
13 url = {https://huggingface.co/DanishMahdi/speecht5_finetuned_sindhi_digits}
14}