adrianstanea commited on
Commit
bca11b0
·
1 Parent(s): 80a102f

Initial upload of Romanian Matcha-TTS models

Browse files

- Add BAS, SGS, and BASE speaker models trained on SWARA 1.0
- Include universal HiFi-GAN vocoder for Romanian TTS
- Provide HuggingFace-compatible model loader
- Add inference examples and configuration files

Signed-off-by: adrianstanea <adrianstanea1@gmail.com>

.gitattributes CHANGED
@@ -1,3 +1,12 @@
 
 
 
 
 
 
 
 
 
1
  *.7z filter=lfs diff=lfs merge=lfs -text
2
  *.arrow filter=lfs diff=lfs merge=lfs -text
3
  *.bin filter=lfs diff=lfs merge=lfs -text
 
1
+ # Git LFS configuration for model files
2
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
3
+ *.pth filter=lfs diff=lfs merge=lfs -text
4
+ *.pt filter=lfs diff=lfs merge=lfs -text
5
+ *.bin filter=lfs diff=lfs merge=lfs -text
6
+ # Vocoder file (without extension in this case)
7
+ models/vocoder/hifigan_univ_v1 filter=lfs diff=lfs merge=lfs -text
8
+ # All model checkpoint files in subdirectories
9
+ models/**/*.ckpt filter=lfs diff=lfs merge=lfs -text
10
  *.7z filter=lfs diff=lfs merge=lfs -text
11
  *.arrow filter=lfs diff=lfs merge=lfs -text
12
  *.bin filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,197 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - ro
5
+ pipeline_tag: text-to-speech
6
+ tags:
7
+ - tts
8
+ - romanian
9
+ - matcha-tts
10
+ - conditional-flow-matching
11
+ - swara
12
+ library_name: pytorch
13
+ datasets:
14
+ - SWARA-1.0
15
+ ---
16
+
17
+ # Matcha-TTS Romanian Models
18
+
19
+ Pre-trained Romanian text-to-speech models based on [Matcha-TTS](https://github.com/shivammehta25/Matcha-TTS) trained on the SWARA 1.0 dataset.
20
+
21
+ ## Quick Start
22
+
23
+ ### Clone Repository
24
+
25
+ Since this repository contains custom inference code and model loading utilities, you need to clone it:
26
+
27
+ ```bash
28
+ # Clone from HuggingFace Hub
29
+ git clone https://huggingface.co/adrianstanea/Ro-Matcha-TTS
30
+ cd Ro-Matcha-TTS
31
+
32
+ # Install Git LFS (if not already installed) to download large model files
33
+ git lfs install
34
+ git lfs pull
35
+ ```
36
+
37
+ ### Installation
38
+
39
+ ```bash
40
+ # Install system dependencies (required for phonemization)
41
+ sudo apt-get install espeak-ng
42
+
43
+ # Install the main Matcha-TTS repository
44
+ pip install git+https://github.com/adrianstanea/Matcha-TTS.git
45
+
46
+ # Install required dependencies
47
+ pip install -r requirements.txt
48
+ ```
49
+
50
+ ### Usage
51
+
52
+ ```python
53
+ import sys
54
+ sys.path.append("src")
55
+ from model_loader import ModelLoader
56
+
57
+ # Load from local cloned repository
58
+ loader = ModelLoader.from_pretrained("./")
59
+
60
+ # List available models
61
+ print(loader.list_models())
62
+ # {'swara': {...}, 'bas_10': {...}, 'bas_950': {...}, ...}
63
+
64
+ # Load production-ready BAS speaker
65
+ model_info = loader.load_models(model="bas_950")
66
+ print(f"Model: {model_info['model_name']}")
67
+ print(f"Path: {model_info['model_path']}")
68
+
69
+ # Load few-shot SGS speaker
70
+ model_info = loader.load_models(model="sgs_10")
71
+ print(f"Training data: {model_info['model_info']['training_data']}")
72
+
73
+ # Use with original Matcha-TTS inference code
74
+ # See examples/inference_example.py for complete usage
75
+ ```
76
+
77
+ ### Run Example
78
+
79
+ ```bash
80
+ cd examples
81
+ python inference_example.py
82
+ ```
83
+
84
+ ## Available Models
85
+
86
+ ### Baseline Model
87
+
88
+ | Model | Type | Description |
89
+ | --------- | -------- | ---------------------------------------------------- |
90
+ | **swara** | Baseline | Speaker-agnostic model trained on full SWARA dataset |
91
+
92
+ ### Fine-tuned Speaker Models
93
+
94
+ | Model | Speaker | Training Samples | Fine-tune Epochs | Use Case |
95
+ | ----------- | ---------- | ---------------- | ---------------- | -------------------------------- |
96
+ | **bas_10** | BAS (Male) | 10 samples | 100 | Few-shot learning / Low-resource |
97
+ | **bas_950** | BAS (Male) | 950 samples | 100 | Production-ready speaker |
98
+ | **sgs_10** | SGS (Male) | 10 samples | 100 | Few-shot learning / Low-resource |
99
+ | **sgs_950** | SGS (Male) | 950 samples | 100 | Production-ready speaker |
100
+
101
+ **Vocoder**: Universal HiFi-GAN vocoder
102
+
103
+ ### Research Methodology
104
+
105
+ - **Training Strategy**: Baseline → Speaker Fine-tuning (100 epochs)
106
+ - **Data Efficiency Study**: 10 vs 950 samples comparison
107
+ - **Low-Resource Learning**: Demonstrates few-shot TTS adaptation
108
+
109
+ ## Model Details
110
+
111
+ - **Architecture**: Matcha-TTS (Conditional Flow Matching)
112
+ - **Dataset**: SWARA 1.0 Romanian Speech Corpus
113
+ - **Sample Rate**: 22,050 Hz
114
+ - **Language**: Romanian (ro)
115
+ - **Text Processing**: eSpeak Romanian phonemizer
116
+ - **Model Size**: ~100M parameters per model
117
+
118
+ ## Repository Structure
119
+
120
+ ```
121
+ ├── models/ # Model checkpoints (Git LFS)
122
+ │ ├── swara/
123
+ │ │ └── matcha-base-1000.ckpt # Baseline model (1000 epochs)
124
+ │ ├── bas/
125
+ │ │ ├── matcha-bas-10_100.ckpt # BAS speaker (10 samples, 100 epochs)
126
+ │ │ └── matcha-bas-950_100.ckpt # BAS speaker (950 samples, 100 epochs)
127
+ │ ├── sgs/
128
+ │ │ ├── matcha-sgs-10_100.ckpt # SGS speaker (10 samples, 100 epochs)
129
+ │ │ └── matcha-sgs-950_100.ckpt # SGS speaker (950 samples, 100 epochs)
130
+ │ └── vocoder/
131
+ │ └── hifigan_univ_v1 # Universal HiFi-GAN vocoder
132
+ ├── configs/
133
+ │ └── config.json # Model configuration
134
+ ├── src/
135
+ │ └── model_loader.py # HuggingFace-compatible loader
136
+ └── examples/
137
+ ├── sample_texts_ro.txt # Sample Romanian texts
138
+ └── inference_example.py # Complete usage example
139
+ ```
140
+
141
+ ## Usage with Original Repository
142
+
143
+ This repository provides model weights and HuggingFace integration. For training, evaluation, and advanced features, use the [main repository](https://github.com/adrianstanea/Matcha-TTS).
144
+
145
+ ```python
146
+ # After loading models with ModelLoader
147
+ from matcha.models.matcha_tts import MatchaTTS
148
+ import torch
149
+
150
+ # Load using paths from ModelLoader
151
+ model = MatchaTTS.load_from_checkpoint(model_info['model_path'])
152
+ # ... continue with original inference code
153
+ ```
154
+
155
+ ## Requirements
156
+
157
+ - Python 3.10
158
+ - Main Matcha-TTS repository for inference
159
+ - HuggingFace Hub for model downloading
160
+
161
+ ## License
162
+
163
+ Same as the original [Matcha-TTS repository](https://github.com/adrianstanea/Matcha-TTS).
164
+
165
+ ## Citation
166
+
167
+ If you use this Romanian adaptation in your research, please cite:
168
+
169
+ ```bibtex
170
+ @ARTICLE{11269795,
171
+ author={Răgman, Teodora and Bogdan Stânea, Adrian and Cucu, Horia and Stan, Adriana},
172
+ journal={IEEE Access},
173
+ title={How Open Is Open TTS? A Practical Evaluation of Open Source TTS Tools},
174
+ year={2025},
175
+ volume={13},
176
+ number={},
177
+ pages={203415-203428},
178
+ keywords={Computer architecture;Training;Text to speech;Spectrogram;Decoding;Computational modeling;Codecs;Predictive models;Acoustics;Low latency communication;Speech synthesis;open tools;evaluation;computational requirements;TTS adaptation;text-to-speech;objective measures;listening test;Romanian},
179
+ doi={10.1109/ACCESS.2025.3637322}
180
+ }
181
+ ```
182
+
183
+ **Original Matcha-TTS Citation:**
184
+
185
+ ```bibtex
186
+ @inproceedings{mehta2024matcha,
187
+ title={Matcha-{TTS}: A fast {TTS} architecture with conditional flow matching},
188
+ author={Mehta, Shivam and Tu, Ruibo and Beskow, Jonas and Sz{\'e}kely, {\'E}va and Henter, Gustav Eje},
189
+ booktitle={Proc. ICASSP},
190
+ year={2024}
191
+ }
192
+ ```
193
+
194
+ ## Links
195
+
196
+ - [Main Repository](https://github.com/adrianstanea/Matcha-TTS) - Training, documentation, and research details
197
+ - [Original Matcha-TTS](https://github.com/shivammehta25/Matcha-TTS) - Base architecture and paper
configs/config.json ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "matcha-tts",
3
+ "language": "romanian",
4
+ "architecture": "conditional_flow_matching",
5
+ "dataset": "SWARA_1.0",
6
+ "sample_rate": 22050,
7
+ "hop_length": 256,
8
+ "win_length": 1024,
9
+ "n_mels": 80,
10
+ "n_fft": 1024,
11
+ "f_min": 0,
12
+ "f_max": 8000,
13
+ "mel_mean": -4.776196479797363,
14
+ "mel_std": 2.2280216217041016,
15
+ "phoneme_cleaners": ["romanian_cleaners"],
16
+ "text_processing": "espeak_romanian",
17
+
18
+ "training_methodology": {
19
+ "baseline": "Speaker-agnostic model trained on full SWARA dataset (21,299 samples)",
20
+ "fine_tuning": "Speaker-specific fine-tuning from baseline for 100 epochs",
21
+ "data_variants": "Comparison of 10 vs 950 samples for fine-tuning effectiveness"
22
+ },
23
+
24
+ "available_models": {
25
+ "swara": {
26
+ "type": "baseline",
27
+ "description": "Speaker-agnostic baseline trained on full SWARA dataset",
28
+ "training_data": "21,299 samples (all speakers)",
29
+ "epochs": "1000",
30
+ "file": "models/swara/matcha-base-1000.ckpt"
31
+ },
32
+ "bas_10": {
33
+ "type": "fine_tuned",
34
+ "speaker": "BAS",
35
+ "description": "BAS speaker fine-tuned with 10 samples",
36
+ "base_model": "swara",
37
+ "training_data": "10 samples",
38
+ "fine_tune_epochs": 100,
39
+ "file": "models/bas/matcha-bas-10_100.ckpt"
40
+ },
41
+ "bas_950": {
42
+ "type": "fine_tuned",
43
+ "speaker": "BAS",
44
+ "description": "BAS speaker fine-tuned with 950 samples",
45
+ "base_model": "swara",
46
+ "training_data": "950 samples",
47
+ "fine_tune_epochs": 100,
48
+ "file": "models/bas/matcha-bas-950_100.ckpt"
49
+ },
50
+ "sgs_10": {
51
+ "type": "fine_tuned",
52
+ "speaker": "SGS",
53
+ "description": "SGS speaker fine-tuned with 10 samples",
54
+ "base_model": "swara",
55
+ "training_data": "10 samples",
56
+ "fine_tune_epochs": 100,
57
+ "file": "models/sgs/matcha-sgs-10_100.ckpt"
58
+ },
59
+ "sgs_950": {
60
+ "type": "fine_tuned",
61
+ "speaker": "SGS",
62
+ "description": "SGS speaker fine-tuned with 950 samples",
63
+ "base_model": "swara",
64
+ "training_data": "950 samples",
65
+ "fine_tune_epochs": 100,
66
+ "file": "models/sgs/matcha-sgs-950_100.ckpt"
67
+ },
68
+ "vocoder": {
69
+ "type": "vocoder",
70
+ "description": "Universal HiFi-GAN vocoder for Romanian TTS",
71
+ "file": "models/vocoder/hifigan_univ_v1"
72
+ }
73
+ },
74
+
75
+ "default_model": "bas_950",
76
+ "research_variants": ["bas_10", "bas_950", "sgs_10", "sgs_950"],
77
+
78
+ "inference_defaults": {
79
+ "n_timesteps": 50,
80
+ "temperature": 0.667,
81
+ "length_scale": 0.95
82
+ }
83
+ }
configs/speaker_config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "speakers": {
3
+ "BAS": {
4
+ "name": "BAS",
5
+ "gender": "male",
6
+ "description": "Primary male speaker from SWARA dataset",
7
+ "total_samples": 1490,
8
+ "variants": {
9
+ "bas_10": {
10
+ "training_samples": 10,
11
+ "description": "Few-shot learning with minimal data",
12
+ "use_case": "Low-resource speaker adaptation"
13
+ },
14
+ "bas_950": {
15
+ "training_samples": 950,
16
+ "description": "High-quality speaker adaptation",
17
+ "use_case": "Production-ready speaker model"
18
+ }
19
+ }
20
+ },
21
+ "SGS": {
22
+ "name": "SGS",
23
+ "gender": "male",
24
+ "description": "Secondary male speaker from SWARA dataset",
25
+ "total_samples": 994,
26
+ "variants": {
27
+ "sgs_10": {
28
+ "training_samples": 10,
29
+ "description": "Few-shot learning with minimal data",
30
+ "use_case": "Low-resource speaker adaptation"
31
+ },
32
+ "sgs_950": {
33
+ "training_samples": 950,
34
+ "description": "High-quality speaker adaptation",
35
+ "use_case": "Production-ready speaker model"
36
+ }
37
+ }
38
+ }
39
+ },
40
+
41
+ "baseline": {
42
+ "swara": {
43
+ "type": "multi_speaker",
44
+ "description": "Speaker-agnostic baseline model",
45
+ "training_samples": 21299,
46
+ "speakers_included": ["BAS", "SGS", "FLO", "others"],
47
+ "use_case": "General Romanian TTS, speaker adaptation base"
48
+ }
49
+ },
50
+
51
+ "research_insights": {
52
+ "data_efficiency": "Compare 10 vs 950 samples for fine-tuning effectiveness",
53
+ "speaker_adaptation": "Baseline + fine-tuning approach for new speakers",
54
+ "low_resource": "Demonstrate few-shot learning capabilities (10 samples)"
55
+ }
56
+ }
examples/inference_example.py ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Example usage of Romanian Matcha-TTS models with HuggingFace integration
3
+
4
+ This script shows how to use the HuggingFace model loader with the original
5
+ Matcha-TTS repository for inference.
6
+ """
7
+
8
+ import sys
9
+ import os
10
+ import torch
11
+ import soundfile as sf
12
+ from pathlib import Path
13
+
14
+ # Add the HuggingFace model loader to path
15
+ sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
16
+
17
+ # Import our model loader
18
+ from model_loader import ModelLoader
19
+
20
+ def load_matcha_dependencies():
21
+ """
22
+ Try to import Matcha-TTS dependencies
23
+
24
+ Make sure you have the main repository installed:
25
+ pip install git+https://github.com/adrianstanea/Matcha-TTS.git
26
+ """
27
+ try:
28
+ # Import from the original Matcha-TTS repository
29
+ from matcha.models.matcha_tts import MatchaTTS
30
+ from matcha.hifigan.models import Generator as HiFiGAN
31
+ from matcha.hifigan.config import v1
32
+ from matcha.hifigan.env import AttrDict
33
+ from matcha.hifigan.denoiser import Denoiser
34
+ from matcha.text import text_to_sequence
35
+ from matcha.utils.utils import intersperse
36
+ return {
37
+ 'MatchaTTS': MatchaTTS,
38
+ 'HiFiGAN': HiFiGAN,
39
+ 'v1': v1,
40
+ 'AttrDict': AttrDict,
41
+ 'Denoiser': Denoiser,
42
+ 'text_to_sequence': text_to_sequence,
43
+ 'intersperse': intersperse
44
+ }
45
+ except ImportError as e:
46
+ print(f"Error importing Matcha-TTS dependencies: {e}")
47
+ print("Please install the main repository:")
48
+ print("pip install git+https://github.com/adrianstanea/Matcha-TTS.git")
49
+ return None
50
+
51
+ def synthesize_romanian(text: str, model: str = "bas_950", repo_path: str = None):
52
+ """
53
+ Synthesize Romanian speech using HuggingFace model loader
54
+
55
+ Args:
56
+ text: Romanian text to synthesize
57
+ model: Model name (swara, bas_10, bas_950, sgs_10, sgs_950)
58
+ repo_path: Path to HuggingFace repo (local or repo ID)
59
+ """
60
+
61
+ # Load Matcha-TTS dependencies
62
+ matcha_deps = load_matcha_dependencies()
63
+ if matcha_deps is None:
64
+ return None
65
+
66
+ # Initialize model loader
67
+ if repo_path is None:
68
+ # Use local path relative to this script
69
+ repo_path = str(Path(__file__).parent.parent)
70
+
71
+ try:
72
+ loader = ModelLoader.from_pretrained(repo_path)
73
+ print(f"✓ Loaded model configuration from {repo_path}")
74
+ except Exception as e:
75
+ print(f"✗ Failed to load model configuration: {e}")
76
+ return None
77
+
78
+ # Get model paths and configuration
79
+ model_info = loader.load_models(model=model)
80
+ print(f"✓ Model info loaded: {model_info['model_name']}")
81
+ print(f" Description: {model_info['model_info']['description']}")
82
+ print(f" Training data: {model_info['model_info'].get('training_data', 'N/A')}")
83
+
84
+ device = torch.device(model_info['device'])
85
+ print(f"✓ Using device: {device}")
86
+
87
+ # Load TTS model
88
+ try:
89
+ model = matcha_deps['MatchaTTS'].load_from_checkpoint(
90
+ model_info['model_path'],
91
+ map_location=device,
92
+ weights_only=False # Required for PyTorch 2.6+ to load OmegaConf configs
93
+ )
94
+ model.eval()
95
+ print(f"✓ Loaded TTS model from {model_info['model_path']}")
96
+ except Exception as e:
97
+ print(f"✗ Failed to load TTS model: {e}")
98
+ return None
99
+
100
+ # Load vocoder
101
+ try:
102
+ h = matcha_deps['AttrDict'](matcha_deps['v1'])
103
+ vocoder = matcha_deps['HiFiGAN'](h).to(device)
104
+ checkpoint = torch.load(model_info['vocoder_path'], map_location=device, weights_only=False)
105
+ vocoder.load_state_dict(checkpoint['generator'])
106
+ vocoder.eval()
107
+ vocoder.remove_weight_norm()
108
+ denoiser = matcha_deps['Denoiser'](vocoder, mode='zeros')
109
+ print(f"✓ Loaded vocoder from {model_info['vocoder_path']}")
110
+ except Exception as e:
111
+ print(f"✗ Failed to load vocoder: {e}")
112
+ return None
113
+
114
+ # Process text
115
+ print(f"Processing text: '{text}'")
116
+ try:
117
+ # Use Romanian cleaners
118
+ x = torch.tensor(
119
+ matcha_deps['intersperse'](
120
+ matcha_deps['text_to_sequence'](text, ['romanian_cleaners'])[0], 0
121
+ ),
122
+ dtype=torch.long,
123
+ device=device
124
+ )[None]
125
+ x_lengths = torch.tensor([x.shape[-1]], dtype=torch.long, device=device)
126
+ print("✓ Text processed successfully")
127
+ except Exception as e:
128
+ print(f"✗ Failed to process text: {e}")
129
+ return None
130
+
131
+ # Generate speech
132
+ print("Generating speech...")
133
+ try:
134
+ with torch.inference_mode():
135
+ # Synthesis parameters from config
136
+ params = model_info['inference_params']
137
+
138
+ output = model.synthesise(
139
+ x, x_lengths,
140
+ n_timesteps=params['n_timesteps'],
141
+ temperature=params['temperature'],
142
+ length_scale=params['length_scale']
143
+ )
144
+
145
+ # Convert to waveform
146
+ mel = output['mel']
147
+ audio = vocoder(mel).clamp(-1, 1)
148
+ audio = denoiser(audio.squeeze(0), strength=0.00025).cpu().squeeze()
149
+
150
+ print("✓ Speech generated successfully")
151
+ return audio.numpy(), model_info['config']['sample_rate']
152
+
153
+ except Exception as e:
154
+ print(f"✗ Failed to generate speech: {e}")
155
+ return None
156
+
157
+ def main():
158
+ """Example usage"""
159
+
160
+ # Test with local repository path
161
+ repo_path = str(Path(__file__).parent.parent) # Path to Ro-Matcha-TTS
162
+
163
+ # Sample Romanian texts
164
+ test_texts = [
165
+ "Bună ziua! Acesta este un test de sinteză vocală.",
166
+ "România are o cultură bogată și o istorie fascinantă.",
167
+ "Limba română face parte din familia limbilor romanice."
168
+ ]
169
+
170
+ # Test different models for research comparison
171
+ test_models = ["bas_10", "bas_950", "sgs_10", "sgs_950"]
172
+
173
+ # Test synthesis
174
+ output_dir = Path("generated_samples")
175
+ output_dir.mkdir(exist_ok=True)
176
+
177
+ for model in test_models: # Test with first two models
178
+ print(f"\n{'='*50}")
179
+ print(f"Testing model: {model}")
180
+ print(f"{'='*50}")
181
+
182
+ for i, text in enumerate(test_texts): # Test with first text
183
+ print(f"\nText {i+1}: {text}")
184
+
185
+ result = synthesize_romanian(
186
+ text=text,
187
+ model=model,
188
+ repo_path=repo_path
189
+ )
190
+
191
+ if result is not None:
192
+ audio, sr = result
193
+ output_file = output_dir / f"sample_{model}_{i+1}.wav"
194
+ sf.write(output_file, audio, sr)
195
+ print(f"✓ Saved audio to {output_file}")
196
+ else:
197
+ print(f"✗ Failed to generate audio for {model}")
198
+
199
+ if __name__ == "__main__":
200
+ main()
examples/sample_texts_ro.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ Bună ziua! Acesta este un test de sinteză vocală în limba română.
2
+ Sistemul de sinteză vocală poate genera vorbire naturală.
3
+ Această tehnologie folosește inteligența artificială avansată.
4
+ Vorbirea sintetizată sună foarte realistă și naturală.
5
+ România are o cultură bogată și o istorie fascinantă.
6
+ Carpații sunt o destinație turistică populară în România.
7
+ Bucureștiul este capitala și cel mai mare oraș din România.
8
+ Limba română face parte din familia limbilor romanice.
9
+ Tehnologia de sinteză vocală continuă să se dezvolte rapid.
models/bas/matcha-bas-10_100.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e38088c0861ea27a3052c913519431d30a898eb103acc66fa76cbce2915c4266
3
+ size 218842881
models/bas/matcha-bas-950_100.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d1685d670ed150a298af0ba101b8ba22dd4ad5c6e5802a3b00caa8ce9f320e98
3
+ size 218842881
models/sgs/matcha-sgs-10_100.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4d5893deb965e7d3456d2be0af1e9974618df18af72c4772b91dc515a5bccf8a
3
+ size 218842881
models/sgs/matcha-sgs-950_100.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:abb84ec60dda560da6ce5f029e17cc4a9effd591bc102c4241ce7f025304648a
3
+ size 218842498
models/swara/matcha-base-1000.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e18fe217b309d2bbf894b9d9ad7263252170f38556a76a1b0e4def95e2caeae
3
+ size 218840902
models/vocoder/hifigan_univ_v1 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:771eaf4876485a35e25577563d390c262e23c2421e4a8c929eacfde34a5b7a60
3
+ size 55788858
requirements.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Core requirements for model loading and inference
2
+ torch>=1.13.0
3
+ huggingface_hub>=0.16.0
4
+ numpy>=1.21.0
5
+ soundfile>=0.10.0
6
+
7
+ # Required for full inference functionality
8
+ # Install the main repository for complete TTS pipeline:
9
+ # pip install git+https://github.com/adrianstanea/Matcha-TTS.git
10
+
11
+ # Text processing dependencies (included in main repo)
12
+ # phonemizer>=3.0.0 # Romanian text processing
13
+ # tqdm>=4.0.0 # Progress bars
14
+
15
+ # Note: The main repository includes all necessary dependencies
16
+ # for loading and using these models with the original inference pipeline
src/__init__.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Matcha-TTS Romanian: HuggingFace Integration
3
+ """
4
+
5
+ from .model_loader import ModelLoader
6
+
7
+ __version__ = "1.0.0"
8
+ __all__ = ["ModelLoader"]
src/model_loader.py ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ HuggingFace-compatible model loader for Romanian Matcha-TTS
3
+ """
4
+
5
+ import json
6
+ import os
7
+ import torch
8
+ from pathlib import Path
9
+ from typing import Optional, Dict, Any
10
+
11
+ try:
12
+ from huggingface_hub import hf_hub_download
13
+ HF_AVAILABLE = True
14
+ except ImportError:
15
+ HF_AVAILABLE = False
16
+
17
+
18
+ class ModelLoader:
19
+ """
20
+ HuggingFace-compatible loader for Romanian Matcha-TTS models
21
+
22
+ Usage:
23
+ loader = ModelLoader.from_pretrained("adrianstanea/Ro-Matcha-TTS")
24
+ model, vocoder = loader.load_models(speaker="BAS")
25
+ """
26
+
27
+ def __init__(self, repo_path: str):
28
+ """
29
+ Initialize with local repository path or HuggingFace repo ID
30
+
31
+ Args:
32
+ repo_path: Path to local repo or HuggingFace repo ID
33
+ """
34
+ self.repo_path = repo_path
35
+ self.config = self._load_config()
36
+
37
+ @classmethod
38
+ def from_pretrained(cls, repo_id: str, cache_dir: Optional[str] = None) -> "ModelLoader":
39
+ """
40
+ Load from HuggingFace Hub or local path
41
+
42
+ Args:
43
+ repo_id: HuggingFace repo ID (e.g., "adrianstanea/Ro-Matcha-TTS") or local path
44
+ cache_dir: Optional cache directory for downloads
45
+
46
+ Returns:
47
+ ModelLoader instance
48
+ """
49
+ if os.path.exists(repo_id):
50
+ # Local path
51
+ return cls(repo_id)
52
+ elif HF_AVAILABLE:
53
+ # Download from HuggingFace Hub
54
+ try:
55
+ config_path = hf_hub_download(
56
+ repo_id=repo_id,
57
+ filename="configs/config.json",
58
+ cache_dir=cache_dir
59
+ )
60
+ repo_cache_path = Path(config_path).parent.parent
61
+ return cls(str(repo_cache_path))
62
+ except Exception as e:
63
+ raise ValueError(f"Could not download from HuggingFace Hub: {e}")
64
+ else:
65
+ raise ImportError("huggingface_hub is required for downloading from HF Hub. Install with: pip install huggingface_hub")
66
+
67
+ def _load_config(self) -> Dict[str, Any]:
68
+ """Load model configuration"""
69
+ config_path = os.path.join(self.repo_path, "configs", "config.json")
70
+ if not os.path.exists(config_path):
71
+ raise FileNotFoundError(f"Config file not found at {config_path}")
72
+
73
+ with open(config_path, 'r') as f:
74
+ return json.load(f)
75
+
76
+ def get_model_path(self, model: str = None) -> str:
77
+ """
78
+ Get path to model checkpoint for specified model
79
+
80
+ Args:
81
+ model: Model name (swara, bas_10, bas_950, sgs_10, sgs_950). If None, uses default.
82
+
83
+ Returns:
84
+ Absolute path to model checkpoint
85
+ """
86
+ if model is None:
87
+ model = self.config["default_model"]
88
+
89
+ if model not in self.config["available_models"]:
90
+ available = list(self.config["available_models"].keys())
91
+ raise ValueError(f"Model '{model}' not available. Available: {available}")
92
+
93
+ model_file = self.config["available_models"][model]["file"]
94
+ model_path = os.path.join(self.repo_path, model_file)
95
+
96
+ if not os.path.exists(model_path):
97
+ # Try to download from HuggingFace if not local
98
+ if HF_AVAILABLE and not os.path.exists(self.repo_path):
99
+ try:
100
+ model_path = hf_hub_download(
101
+ repo_id=self.repo_path, # Treat as repo_id if not local path
102
+ filename=model_file
103
+ )
104
+ except Exception as e:
105
+ raise FileNotFoundError(f"Model file not found locally and could not download: {e}")
106
+ else:
107
+ raise FileNotFoundError(f"Model file not found: {model_path}")
108
+
109
+ return model_path
110
+
111
+ def get_vocoder_path(self) -> str:
112
+ """
113
+ Get path to vocoder checkpoint
114
+
115
+ Returns:
116
+ Absolute path to vocoder checkpoint
117
+ """
118
+ vocoder_file = self.config["available_models"]["vocoder"]["file"]
119
+ vocoder_path = os.path.join(self.repo_path, vocoder_file)
120
+
121
+ if not os.path.exists(vocoder_path):
122
+ # Try to download from HuggingFace if not local
123
+ if HF_AVAILABLE and not os.path.exists(self.repo_path):
124
+ try:
125
+ vocoder_path = hf_hub_download(
126
+ repo_id=self.repo_path,
127
+ filename=vocoder_file
128
+ )
129
+ except Exception as e:
130
+ raise FileNotFoundError(f"Vocoder file not found locally and could not download: {e}")
131
+ else:
132
+ raise FileNotFoundError(f"Vocoder file not found: {vocoder_path}")
133
+
134
+ return vocoder_path
135
+
136
+ def load_models(self, model: str = None, device: str = "auto"):
137
+ """
138
+ Load TTS model and vocoder for inference
139
+
140
+ NOTE: This returns paths for use with the original Matcha-TTS repository.
141
+ You'll need to import and use the original loading functions.
142
+
143
+ Args:
144
+ model: Model to load (swara, bas_10, bas_950, sgs_10, sgs_950)
145
+ device: Device to load on ("auto", "cpu", "cuda")
146
+
147
+ Returns:
148
+ Dict with model and vocoder paths and configurations
149
+ """
150
+ if device == "auto":
151
+ device = "cuda" if torch.cuda.is_available() else "cpu"
152
+
153
+ model_path = self.get_model_path(model)
154
+ vocoder_path = self.get_vocoder_path()
155
+
156
+ model_name = model or self.config["default_model"]
157
+ model_info = self.config["available_models"][model_name]
158
+
159
+ return {
160
+ "model_path": model_path,
161
+ "vocoder_path": vocoder_path,
162
+ "config": self.config,
163
+ "model_name": model_name,
164
+ "model_info": model_info,
165
+ "device": device,
166
+ "inference_params": self.config["inference_defaults"]
167
+ }
168
+
169
+ def list_models(self):
170
+ """List available models with details"""
171
+ models = {}
172
+ for name, info in self.config["available_models"].items():
173
+ if name != "vocoder":
174
+ models[name] = {
175
+ "type": info["type"],
176
+ "description": info["description"],
177
+ "speaker": info.get("speaker", "multi_speaker"),
178
+ "training_data": info.get("training_data", "N/A")
179
+ }
180
+ return models
181
+
182
+ def list_research_variants(self):
183
+ """List research comparison variants"""
184
+ return self.config["research_variants"]
185
+
186
+ def get_model_info(self, model: str = None):
187
+ """Get detailed information about a specific model"""
188
+ model_name = model or self.config["default_model"]
189
+ if model_name not in self.config["available_models"]:
190
+ raise ValueError(f"Model '{model_name}' not available")
191
+
192
+ return self.config["available_models"][model_name]
193
+
194
+ def get_sample_texts(self) -> list:
195
+ """Get Romanian sample texts for testing"""
196
+ return [
197
+ "Bună ziua! Acesta este un test de sinteză vocală în limba română.",
198
+ "Matcha-TTS funcționează foarte bine pentru limba română.",
199
+ "Sistemul de sinteză vocală poate genera vorbire naturală.",
200
+ "Această tehnologie folosește inteligența artificială avansată.",
201
+ "Vorbirea sintetizată sună foarte realistă și naturală."
202
+ ]
test.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ sys.path.append("src")
3
+ from model_loader import ModelLoader
4
+
5
+ # Load from HuggingFace Hub (when available)
6
+ loader = ModelLoader.from_pretrained("adrianstanea/Ro-Matcha-TTS")
7
+
8
+ # Or load from local path
9
+ loader = ModelLoader.from_pretrained("./")
10
+
11
+ # List available models
12
+ print(loader.list_models())
13
+ # {'swara': {...}, 'bas_10': {...}, 'bas_950': {...}, ...}
14
+
15
+ # Load production-ready BAS speaker
16
+ model_info = loader.load_models(model="bas_950")
17
+ print(f"Model: {model_info['model_name']}")
18
+ print(f"Path: {model_info['model_path']}")
19
+
20
+ # Load few-shot SGS speaker
21
+ model_info = loader.load_models(model="sgs_10")
22
+ print(f"Training data: {model_info['model_info']['training_data']}")