This repository provides a guide on how to prepare a dataset and execute fine-tuning using the StyleTTS2 process. https://github.com/yl4579/StyleTTS2
The scripts are compatible with WSL2 and Linux. Windows requires additional dependencies and might not be worth the effort.
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 -U
pip install git+https://github.com/m-bain/whisperx.git
pip install phonemizer pydub pysrt tqdm
Change directory to where you have unpacked StyleTTSFineTune (You should see the makeDataset folder)
To make base directories you can run segmenter script. It will create the folders.
python srtsegmenter.pyAdd WAV audio file/s to the audio directory (remove special characters, brackets, parenthesis to prevent issues)
**** This step isnt mandatory **** for the training process. You can run whisperx and segmentation without adding silence. If you do want to add silence then silencebuffer.py within the tools folder will go over your audio file, find the silent portions between sentences/breaks in speech, and add a specific length of silence to them. This could in theory provide a more accurate cut during the segmentation process. You MUST adjust the parameters within the script to fit your data. I left the values that worked for my dataset in the code, you can try them as defaults if you wish.
Run the following command to generate srt files for all files in the audio folder:
Linux -
for i in ../audio/*.wav; do whisperx "$i" --model large-v3 --output_format srt --condition_on_previous_text True --max_line_width 250 --max_line_count 1 --segment_resolution sentence --align_model WAV2VEC2_ASR_LARGE_LV60K_960H; done
Windows - in a powershell terminal copy and paste the following after verifying path to audio folder:
Get-ChildItem -Path 'C:\path\to\wav\folder' -Filter *.wav | ForEach-Object { whisperx $_.FullName --model large-v2 --align_model WAV2VEC2_ASR_LARGE_LV60K_960H }
This will generate a Whisperx .SRT file transcription of your audio. Place the srt file/s into the srt folder
The above steps will generate a set of segmented audio files, a folder of bad audio it didn't like, and an output.txt file. I have it set to throw out segmemts under 1 second and over 11.6 seconds. You can adjust this to varying degrees.
Clone the StyleTTS2 repository and navigate to its directory:
Install the required packages:
Prepare the data and model:
Download the StyleTTS2-LibriTTS model and place it in the Models/LibriTTS directory.
If the language of your dataset is not English, you will need to modify the PLBER model of StyleTTS. If this is your case, refer to this repository (don't forget to check if your language is supported).
Finally, you can start the fine-tuning process with the following command:
Python
59.5%
Jupyter Notebook
40.5%
This repository provides a guide on how to prepare a dataset and execute fine-tuning using the StyleTTS2 process. https://github.com/yl4579/StyleTTS2
The scripts are compatible with WSL2 and Linux. Windows requires additional dependencies and might not be worth the effort.
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 -U
pip install git+https://github.com/m-bain/whisperx.git
pip install phonemizer pydub pysrt tqdm
Change directory to where you have unpacked StyleTTSFineTune (You should see the makeDataset folder)
To make base directories you can run segmenter script. It will create the folders.
python srtsegmenter.pyAdd WAV audio file/s to the audio directory (remove special characters, brackets, parenthesis to prevent issues)
**** This step isnt mandatory **** for the training process. You can run whisperx and segmentation without adding silence. If you do want to add silence then silencebuffer.py within the tools folder will go over your audio file, find the silent portions between sentences/breaks in speech, and add a specific length of silence to them. This could in theory provide a more accurate cut during the segmentation process. You MUST adjust the parameters within the script to fit your data. I left the values that worked for my dataset in the code, you can try them as defaults if you wish.
Run the following command to generate srt files for all files in the audio folder:
Linux -
for i in ../audio/*.wav; do whisperx "$i" --model large-v3 --output_format srt --condition_on_previous_text True --max_line_width 250 --max_line_count 1 --segment_resolution sentence --align_model WAV2VEC2_ASR_LARGE_LV60K_960H; done
Windows - in a powershell terminal copy and paste the following after verifying path to audio folder:
Get-ChildItem -Path 'C:\path\to\wav\folder' -Filter *.wav | ForEach-Object { whisperx $_.FullName --model large-v2 --align_model WAV2VEC2_ASR_LARGE_LV60K_960H }
This will generate a Whisperx .SRT file transcription of your audio. Place the srt file/s into the srt folder
The above steps will generate a set of segmented audio files, a folder of bad audio it didn't like, and an output.txt file. I have it set to throw out segmemts under 1 second and over 11.6 seconds. You can adjust this to varying degrees.
Clone the StyleTTS2 repository and navigate to its directory:
Install the required packages:
Prepare the data and model:
Download the StyleTTS2-LibriTTS model and place it in the Models/LibriTTS directory.
If the language of your dataset is not English, you will need to modify the PLBER model of StyleTTS. If this is your case, refer to this repository (don't forget to check if your language is supported).
Finally, you can start the fine-tuning process with the following command:
Python
59.5%
Jupyter Notebook
40.5%