@echo off
setlocal enabledelayedexpansion

REM Get the dropped file's path
set INPUT_FILE=%1
echo Input file: %INPUT_FILE%

REM Run pre_process_given_text_file.py with the dropped file as input
echo Running pre_process_given_text_file.py...
python pre_process_given_text_file.py --input_file %INPUT_FILE%


set "PROCESSED_TEXT="

REM Read the contents of a file line by line
for /F "delims=" %%A in ('findstr "^" processed_speech.txt') do (
    Setlocal DisableDelayedExpansion
    set "LINE=%%A"
    Setlocal EnableDelayedExpansion
    set "line=!line:*:=!"
    set "line=!line:"=""q!"
    set "line=!line:^=^^!"
    call set "line=%%line:^!=""c^!%%"
    set "line=!line:""c=^!"
    set "line=!line:""q="!"
    FOR /F "delims=" %%B in (""!line!"") do (
      endlocal
      endlocal
      if defined PROCESSED_TEXT (
        set "PROCESSED_TEXT=!PROCESSED_TEXT!; %%~B" !
      ) ELSE (
        set "PROCESSED_TEXT=%%~B" !
      )
    )
)

echo Processed text: !PROCESSED_TEXT!


REM Activate the virtual environment
echo Activating virtual environment...
REM in the below path, this part "F:\voice clone tutorial\, replace it with yours installation 
call "F:\voice clone tutorial\tortoise-tts-fast\venv\Scripts\activate.bat"

REM Change directory to the tortoise_tts.py script location
REM in the below path, this part "F:\voice clone tutorial\, replace it with yours installation 
cd "F:\voice clone tutorial\tortoise-tts-fast\scripts"

REM Run the tortoise_tts.py command with the read text
REM change F:\DL-Art-School\experiments\test2\models\1480_gpt.pth with your trained models\1480_gpt
REM change output folder as you wish F:\voice clone tutorial\out2
REM you can reduce diffusion_iterations but higher is supposed to be better
REM you can change  --preset depending on your GPU : ultra_fast - fast - standard - high_quality and the time you want to render
REM --text_split dont matter since it will always split with ; character. you can also change this character if you wish in python files
REM weaker GPU command below
REM python tortoise_tts.py --output_dir "F:\voice clone tutorial\out6" --seed 1 --preset ultra_fast --ar_checkpoint "F:\DL-Art-School\experiments\test2\models\1480_gpt.pth" --text_split "gg" "%PROCESSED_TEXT%"

REM according to my tests preset really makes difference. standard is really good

REM change the settings accordingly
REM DO NOT PUT SPACES BEFORE OR AFTER = . SO CHANGE ONLY PATH
set outputdir="F:\voice clone tutorial\voicesdir_test"
set training_checkpoint_file="F:\voice clone tutorial\check_point_tests\1120_gpt.pth"

echo Running tortoise_tts.py...
python tortoise_tts.py --candidates 1 --voicefixer True --no_cache False --half False --low_vram True --vocoder "BigVGAN" --output_dir !outputdir! --diffusion_iterations 250 --seed 1 --preset fast --ar_checkpoint !training_checkpoint_file! --text_split "gg" "!PROCESSED_TEXT!"

REM Deactivate the virtual environment
endlocal

echo Script execution complete. Press any key to exit.
pause >nul
