|
from transformers import ParlerTTSForConditionalGeneration, AutoTokenizer, Trainer, TrainingArguments |
|
from datasets import load_dataset |
|
|
|
|
|
model_name = "parler-tts/parler-tts-mini-v1" |
|
model = ParlerTTSForConditionalGeneration.from_pretrained(model_name) |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
|
|
|
|
dataset = load_dataset("lj_speech") |
|
|
|
|
|
def preprocess_function(examples): |
|
|
|
inputs = tokenizer(examples["text"], return_tensors="pt", padding=True, truncation=True) |
|
|
|
return {"input_ids": inputs["input_ids"], "attention_mask": inputs["attention_mask"]} |
|
|
|
train_dataset = dataset["train"].map(preprocess_function, batched=True) |
|
|
|
|
|
training_args = TrainingArguments( |
|
output_dir="./tts_finetuned", |
|
per_device_train_batch_size=8, |
|
num_train_epochs=3, |
|
save_steps=500, |
|
logging_steps=10, |
|
) |
|
|
|
|
|
trainer = Trainer( |
|
model=model, |
|
args=training_args, |
|
train_dataset=train_dataset, |
|
) |
|
|
|
|
|
trainer.train() |
|
|
|
|
|
trainer.save_model("./tts_finetuned") |
|
tokenizer.save_pretrained("./tts_finetuned") |
|
|
|
print("TTS model fine-tuned and saved to './tts_finetuned'. Upload to models/tts_model in your Space.") |