Text-to-Speech
Transformers
Safetensors
English
parler_tts
text2text-generation
annotation
bigband commited on
Commit
32b37bf
·
verified ·
1 Parent(s): 3dfb78f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +363 -0
README.md ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags:
4
+ - text-to-speech
5
+ - annotation
6
+ license: apache-2.0
7
+ language:
8
+ - en
9
+ pipeline_tag: text-to-speech
10
+ inference: false
11
+ datasets:
12
+ - ylacombe/expresso
13
+ - reach-vb/jenny_tts_dataset
14
+ - blabble-io/libritts_r
15
+ ---
16
+
17
+ <img src="https://huggingface.co/datasets/parler-tts/images/resolve/main/thumbnail.png" alt="Parler Logo" width="800" style="margin-left:'auto' margin-right:'auto' display:'block'"/>
18
+
19
+
20
+ # Parler-TTS Mini: Expresso
21
+
22
+ <a target="_blank" href="https://huggingface.co/spaces/parler-tts/parler-tts-expresso">
23
+ <img src="https://huggingface.co/datasets/huggingface/badges/raw/main/open-in-hf-spaces-sm.svg" alt="Open in HuggingFace"/>
24
+ </a>
25
+
26
+ **Parler-TTS Mini: Expresso** is a fine-tuned version of [Parler-TTS Mini v0.1](https://huggingface.co/parler-tts/parler_tts_mini_v0.1)
27
+ on the [Expresso](https://huggingface.co/datasets/ylacombe/expresso) dataset. It is a lightweight text-to-speech (TTS)
28
+ model that can generate high-quality, natural sounding speech. Compared to the original model, Parler-TTS Expresso provides
29
+ superior control over **emotions** (happy, confused, laughing, sad) and **consistent voices** (Jerry, Thomas, Elisabeth, Talia).
30
+
31
+ It is part of the first release from the [Parler-TTS](https://github.com/huggingface/parler-tts) project, which aims to
32
+ provide the community with TTS training resources and dataset pre-processing code. Details for reproducing this entire
33
+ training run are provided in the section [Training Procedure](#training-procedure).
34
+
35
+ ## Usage
36
+
37
+ Using Expresso is as simple as "bonjour". Simply install the library from source:
38
+
39
+ ```sh
40
+ pip install git+https://github.com/huggingface/parler-tts.git
41
+ ```
42
+
43
+ You can then use the model with the following inference snippet:
44
+
45
+ ```py
46
+ import torch
47
+ from parler_tts import ParlerTTSForConditionalGeneration
48
+ from transformers import AutoTokenizer, set_seed
49
+ import soundfile as sf
50
+
51
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
52
+
53
+ model = ParlerTTSForConditionalGeneration.from_pretrained("parler-tts/parler-tts-mini-expresso").to(device)
54
+ tokenizer = AutoTokenizer.from_pretrained("parler-tts/parler-tts-mini-expresso")
55
+
56
+ prompt = "Why do you make me do these examples? They're *so* generic."
57
+ description = "Thomas speaks moderately slowly in a sad tone with emphasis and high quality audio."
58
+
59
+ input_ids = tokenizer(description, return_tensors="pt").input_ids.to(device)
60
+ prompt_input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
61
+
62
+ set_seed(42)
63
+ generation = model.generate(input_ids=input_ids, prompt_input_ids=prompt_input_ids)
64
+ audio_arr = generation.cpu().numpy().squeeze()
65
+ sf.write("parler_tts_out.wav", audio_arr, model.config.sampling_rate)
66
+ ```
67
+
68
+ **Tips**:
69
+ * Specify the name of a male speaker (Jerry, Thomas) or female speaker (Talia, Elisabeth) for consistent voices
70
+ * The model can generate in a range of emotions, including: "happy", "confused", "default" (meaning no particular emotion conveyed), "laughing", "sad", "whisper", "emphasis"
71
+ * Include the term "high quality audio" to generate the highest quality audio, and "very noisy audio" for high levels of background noise
72
+ * Punctuation can be used to control the prosody of the generations, e.g. use commas to add small breaks in speech
73
+ * To emphasise particular words, wrap them in asterisk (e.g. `*you*` in the example above) and include "emphasis" in the prompt
74
+
75
+ ## Training Procedure
76
+
77
+ Expresso is a high-quality, expressive speech dataset that includes samples from four speakers (two male, two female).
78
+ By fine-tuning Parler-TTS Mini v0.1 on this dataset, we can train the model to follow emotion and speaker prompts.
79
+
80
+ To reproduce this fine-tuning run, we need to perform two steps:
81
+ 1. Create text descriptions from the audio samples in the Expresso dataset
82
+ 2. Train the model on the (text, audio) pairs
83
+
84
+ Step 1 is performed using the [DataSpeech](https://github.com/huggingface/dataspeech) library, and step 2 using
85
+ [Parler-TTS](https://github.com/huggingface/parler-tts). Should you wish to use the pre-annotated dataset from our
86
+ experiments, you can jump straight to [step 2](#step-2--fine-tune-the-model). For both, you can follow step 0 for
87
+ getting set-up.
88
+
89
+ ### Step 0: Set-Up
90
+
91
+ We'll start by creating a fresh Python environment:
92
+
93
+ ```sh
94
+ python3 -m venv parler-env
95
+ source parler-env/bin/activate
96
+ ```
97
+
98
+ Next, install PyTorch according to the [official instructions](https://pytorch.org/get-started/locally/). We can then
99
+ install DataSpeech and Parler-TTS sequentially:
100
+
101
+ ```sh
102
+ git clone git@github.com:huggingface/dataspeech.git && cd dataspeech && pip install -r requirements.txt
103
+ cd ..
104
+ git clone https://github.com/huggingface/parler-tts.git && cd parler-tts && pip install -e ."[train]"
105
+ cd ..
106
+ ```
107
+
108
+ You can link your Hugging Face account so that you can push model repositories on the Hub. This will allow you to save
109
+ your trained models on the Hub so that you can share them with the community. Simply run the command:
110
+
111
+ ```sh
112
+ git config --global credential.helper store
113
+ huggingface-cli login
114
+ ```
115
+
116
+ And then enter an authentication token from https://huggingface.co/settings/tokens. Create a new token if you do not
117
+ have one already. You should make sure that this token has "write" privileges.
118
+
119
+ You also have the option to configure Accelerate by running the following command. Note that you should set the number
120
+ of GPUs you wish to use for training/inference, and also the data type (dtype) based on your device (e.g. bfloat16 on
121
+ A100 GPUs, float16 on V100 GPUs, etc.):
122
+
123
+ ```sh
124
+ accelerate config
125
+ ```
126
+
127
+ Optionally, you can also login to Weights and Biases for automatic logging:
128
+
129
+ ```sh
130
+ wandb login
131
+ ```
132
+
133
+ ### Step 1: Create Text Descriptions
134
+
135
+ Creating text descriptions for the dataset comprises three sub-stages from DataSpeech, which we'll cover below.
136
+
137
+ #### 1.A. Annotate the Expresso dataset
138
+
139
+ We'll use the [`main.py`](https://github.com/huggingface/dataspeech/blob/main/main.py) file from DataSpeech to label
140
+ the following continuous variables:
141
+ - Speaking rate
142
+ - Signal-to-noise ratio (SNR)
143
+ - Reverberation
144
+ - Speech monotony
145
+
146
+ This can be done with the following command:
147
+ ```sh
148
+ python ./dataspeech/main.py "ylacombe/expresso" \
149
+ --configuration "default" \
150
+ --text_column_name "text" \
151
+ --audio_column_name "audio" \
152
+ --cpu_num_workers 8 \
153
+ --rename_column \
154
+ --repo_id "expresso-tags"
155
+ ```
156
+
157
+ Note that the script will be faster if you have GPUs at your disposal. It will automatically scale up to every GPU available in your environment. To control which GPUs to run the script on consider indicating via `CUDA_VISIBLE_DEVICES` environment variable.
158
+
159
+ The resulting dataset will be pushed to the Hugging Face Hub under your Hugging Face handle. Mine was pushed to [reach-vb/expresso-tags](https://huggingface.co/datasets/reach-vb/expresso-tags).
160
+ We can see that the dataset is annotated with continuous features like "speaking_rate" and "snr".
161
+
162
+ #### 1.B. Map annotations to text bins
163
+
164
+ The next step involves mapping the continuous variables to discrete ones. This is achieved by binning the continuous variables
165
+ into buckets, and assigning each one a text label.
166
+
167
+ Since the ultimate goal here is to fine-tune the [Parler-TTS v0.1 checkpoint](https://huggingface.co/parler-tts/parler_tts_mini_v0.1)
168
+ on the Expresso dataset, we want to stay consistent with the text bins of the dataset on which the original model was trained.
169
+
170
+ To do this, we'll pass [`v01_bin_edges.json`](https://github.com/huggingface/dataspeech/blob/main/examples/tags_to_annotations/v01_bin_edges.json)
171
+ as an input argument to our script, which holds the bin edges from the original dataset:
172
+
173
+ ```sh
174
+ python ./dataspeech/scripts/metadata_to_text.py \
175
+ "reach-vb/expresso-tags" \
176
+ --repo_id "expresso-tags" \
177
+ --configuration "default" \
178
+ --cpu_num_workers "8" \
179
+ --path_to_bin_edges "./examples/tags_to_annotations/v01_bin_edges.json" \
180
+ --avoid_pitch_computation
181
+ ```
182
+
183
+ Since we leverage the bins from the original dataset, the above script only takes a few seconds. The resulting dataset
184
+ will be pushed to the Hugging Face Hub under your Hugging Face handle. Mine was pushed to [reach-vb/expresso-tags](https://huggingface.co/datasets/reach-vb/expresso-tags).
185
+
186
+ You can notice that text bins such as "slightly noisy", "quite monotone" have been added to the samples.
187
+
188
+ #### 1.C. Create natural language descriptions from those text bins
189
+
190
+ Now that we have text bins associated to the Expresso dataset, the next step is to create natural language descriptions.
191
+ This involves passing the text bins to a large-language model (LLM), and have it generate corresponding descriptions.
192
+
193
+ There is a template [prompt creation script](https://github.com/huggingface/dataspeech/blob/main/scripts/run_prompt_creation.py)
194
+ in Parler-TTS which can be used to generate descriptions from the features tagged in [step 1.A](#1a-annotate-the-expresso-dataset) (reverberation, noise, speaking rate, etc).
195
+
196
+ However, not all of these features are relevant for the Expresso dataset. For instance, Expresso was recorded in a
197
+ professional recording studio, so all the samples are high quality. Thus, we chose to create prompts with the following subset of features:
198
+ 1. Name: we mapped the speaker ids (ex1, ex2, ex3, ex4) to unique speaker names (Jerry, Elisabeth, Thomas, Talia). This encourages the model to learn specific speakers from the training data
199
+ 2. Emotion: we include the emotion provided in the Expresso dataset
200
+ 3. Speaking rate: we use the pre-computed text bins from the previous step
201
+
202
+ 4. In addition, we also hard-coded the quality of the audio to be "very high-quality", given the studio recording conditions.
203
+
204
+ As an example, if we passed:
205
+ 1. Speaker: Jerry
206
+ 2. Emotion: confused
207
+ 3. Speaking rate: moderate speed
208
+
209
+ We would expect to generate a sample along the lines of: "Jerry speaks with a confused tone and at a moderate speed with high quality audio."
210
+
211
+ The modified prompt creation script can be found in this repository. You can download this script with the following Python command:
212
+
213
+ ```python
214
+ from huggingface_hub import hf_hub_download
215
+
216
+ hf_hub_download(repo_id="parler-tts/parler-tts-mini-expresso", filename="run_prompt_creation.py", local_dir="./run_prompt_creation_expresso.py")
217
+ ```
218
+
219
+ You can then launch prompt creation using the [Mistral Instruct 7B](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2)
220
+ model with the following command:
221
+
222
+ ```sh
223
+ accelerate launch ./dataspeech/run_prompt_creation_expresso.py \
224
+ --dataset_name "reach-vb/expresso-tags" \
225
+ --dataset_config_name "default" \
226
+ --model_name_or_path "mistralai/Mistral-7B-Instruct-v0.2" \
227
+ --per_device_eval_batch_size 32 \
228
+ --attn_implementation "sdpa" \
229
+ --dataloader_num_workers 8 \
230
+ --output_dir "./tmp_expresso" \
231
+ --load_in_4bit \
232
+ --push_to_hub \
233
+ --hub_dataset_id "expresso-tagged-w-speech-mistral" \
234
+ --preprocessing_num_workers 16
235
+ ```
236
+
237
+ Note that the Mistral model is gated, so you should ensure you have accepted the terms-of-use from the [model card](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2).
238
+ You can find the annotated dataset under TODO [reach-vb/expresso-tagged-w-speech-mistral](https://huggingface.co/datasets/reach-vb/expresso-tagged-w-speech-mistral),
239
+ where you'll find sensible descriptions from the features that we passed.
240
+
241
+ This step generally demands more resources and times and should use one or many GPUs. Scaling to multiple GPUs using [distributed data parallelism (DDP)](https://pytorch.org/tutorials/beginner/ddp_series_theory.html)
242
+ is trivial: simply run `accelerate config` and select the multi-GPU option, specifying the IDs of the GPUs you wish to use. The
243
+ above script can then be run using DDP with no code changes.
244
+
245
+ If you are resource constrained and need to use a smaller model, [Gemma 2B](https://huggingface.co/google/gemma-2b-it)
246
+ is an excellent choice.
247
+
248
+ ### Step 2: Fine-Tune the Model
249
+
250
+ Fine-tuning is performed using the Parler-TTS training script [run_parler_tts_training.py](https://github.com/huggingface/parler-tts/blob/main/training/run_parler_tts_training.py).
251
+ It is the same script used to pre-train the model, and can be used for fine-tuning without any code-changes.
252
+
253
+ To preserve the model's ability to generate speech with generic voice descriptions, such as in the style of
254
+ [Parler-TTS Mini v0.1](https://huggingface.co/parler-tts/parler_tts_mini_v0.1), we fine-tuned the model
255
+ on a combination of three datasets, including the test split of LibriTTS-R:
256
+ 1. [Expresso](https://huggingface.co/datasets/ylacombe/expresso)
257
+ 2. [Jenny](https://huggingface.co/datasets/reach-vb/jenny_tts_dataset)
258
+ 3. [LibriTTS-R](https://huggingface.co/datasets/blabble-io/libritts_r)
259
+
260
+ This was achieved through the following command:
261
+
262
+ ```sh
263
+ accelerate launch ./training/run_parler_tts_training.py \
264
+ --model_name_or_path "parler-tts/parler_tts_mini_v0.1" \
265
+ --feature_extractor_name "parler-tts/dac_44khZ_8kbps" \
266
+ --description_tokenizer_name "parler-tts/parler_tts_mini_v0.1" \
267
+ --prompt_tokenizer_name "parler-tts/parler_tts_mini_v0.1" \
268
+ --report_to "wandb" \
269
+ --overwrite_output_dir true \
270
+ --train_dataset_name "ylacombe/expresso+reach-vb/jenny_tts_dataset+blabble-io/libritts_r+blabble-io/libritts_r" \
271
+ --train_metadata_dataset_name "reach-vb/expresso-tagged-w-speech-mistral-v3+ylacombe/jenny-tts-10k-tagged+parler-tts/libritts_r_tags_tagged_10k_generated+parler-tts/libritts_r_tags_tagged_10k_generated" \
272
+ --train_dataset_config_name "read+default+clean+other" \
273
+ --train_split_name "train+train[:20%]+test.clean+test.other" \
274
+ --eval_dataset_name "ylacombe/expresso+reach-vb/jenny_tts_dataset+blabble-io/libritts_r+blabble-io/libritts_r" \
275
+ --eval_metadata_dataset_name "reach-vb/expresso-tagged-w-speech-mistral-v3+ylacombe/jenny-tts-10k-tagged+parler-tts/libritts_r_tags_tagged_10k_generated+parler-tts/libritts_r_tags_tagged_10k_generated" \
276
+ --eval_dataset_config_name "read+default+clean+other" \
277
+ --eval_split_name "train+train[:20%]+test.clean+test.other" \
278
+ --max_eval_samples 8 \
279
+ --per_device_eval_batch_size 16 \
280
+ --target_audio_column_name "audio" \
281
+ --description_column_name "text_description" \
282
+ --prompt_column_name "text" \
283
+ --max_duration_in_seconds 30.0 \
284
+ --min_duration_in_seconds 2.0 \
285
+ --max_text_length 400 \
286
+ --preprocessing_num_workers 2 \
287
+ --do_train true \
288
+ --num_train_epochs 8 \
289
+ --gradient_accumulation_steps 8 \
290
+ --gradient_checkpointing true \
291
+ --per_device_train_batch_size 16 \
292
+ --learning_rate 0.00008 \
293
+ --adam_beta1 0.9 \
294
+ --adam_beta2 0.99 \
295
+ --weight_decay 0.01 \
296
+ --lr_scheduler_type "cosine" \
297
+ --warmup_steps 250 \
298
+ --logging_steps 2 \
299
+ --freeze_text_encoder true \
300
+ --audio_encoder_per_device_batch_size 4 \
301
+ --dtype "bfloat16" \
302
+ --seed 456 \
303
+ --output_dir "./parler-tts-mini-expresso" \
304
+ --temporary_save_to_disk "./audio_code_tmp" \
305
+ --save_to_disk "./tmp_dataset_audio" \
306
+ --dataloader_num_workers 4 \
307
+ --do_eval \
308
+ --predict_with_generate \
309
+ --include_inputs_for_metrics \
310
+ --group_by_length true
311
+ ```
312
+
313
+ On a single 80GB A100 GPU, training took approximately 1.5 hours and returned a final evaluation loss of 4.0. Again, the
314
+ script can be configured for multiple GPUs by running `accelerate config` from the command line; no further
315
+ code-changes are required.
316
+
317
+ Training performance is quite sensitive to learning rate and number of epochs: you should tune these according to your task
318
+ and the size of your dataset. In our experiments, we found the best performance to occur after 8 epochs of training
319
+ with a learning rate of 8e-5.
320
+
321
+ If you followed to the end of these steps: congratulations! You should now have a fine-tuned model you can use for your
322
+ downstream applications using the [inference code-example](#usage) above. You can try substituting your own dataset, or
323
+ run training using a single-speaker dataset, like the [Jenny example](https://colab.research.google.com/github/ylacombe/scripts_and_notebooks/blob/main/Finetuning_Parler_TTS_on_a_single_speaker_dataset.ipynb).
324
+
325
+ ## Motivation
326
+
327
+ Parler-TTS is a reproduction of work from the paper [Natural language guidance of high-fidelity text-to-speech with synthetic annotations](https://www.text-description-to-speech.com) by Dan Lyth and Simon King, from Stability AI and Edinburgh University respectively.
328
+
329
+ Contrarily to other TTS models, Parler-TTS is a **fully open-source** release. All datasets, pre-processing, training code and weights are released publicly under permissive license, enabling the community to build on our work and develop their own powerful TTS models.
330
+ Parler-TTS was released alongside:
331
+ * [The Parler-TTS repository](https://github.com/huggingface/parler-tts) - you can train and fine-tuned your own version of the model.
332
+ * [The Data-Speech repository](https://github.com/huggingface/dataspeech) - a suite of utility scripts designed to annotate speech datasets.
333
+ * [The Parler-TTS organization](https://huggingface.co/parler-tts) - where you can find the annotated datasets as well as the future checkpoints.
334
+
335
+ ## Citation
336
+
337
+ If you found this repository useful, please consider citing this work and also the original Stability AI paper:
338
+
339
+ ```
340
+ @misc{lacombe-etal-2024-parler-tts,
341
+ author = {Yoach Lacombe and Vaibhav Srivastav and Sanchit Gandhi},
342
+ title = {Parler-TTS},
343
+ year = {2024},
344
+ publisher = {GitHub},
345
+ journal = {GitHub repository},
346
+ howpublished = {\url{https://github.com/huggingface/parler-tts}}
347
+ }
348
+ ```
349
+
350
+ ```
351
+ @misc{lyth2024natural,
352
+ title={Natural language guidance of high-fidelity text-to-speech with synthetic annotations},
353
+ author={Dan Lyth and Simon King},
354
+ year={2024},
355
+ eprint={2402.01912},
356
+ archivePrefix={arXiv},
357
+ primaryClass={cs.SD}
358
+ }
359
+ ```
360
+
361
+ ## License
362
+
363
+ This model is permissively licensed under the Apache 2.0 license.