33import os
44import re
55
6- @Gooey (program_name = 'whisper.cppGUI' ,
6+ @Gooey (program_name = 'whisper.cppGUI' ,
77 menu = [{'name' : 'File' ,
88 'items' : [{
99 'type' : 'AboutDialog' ,
@@ -61,13 +61,7 @@ def main():
6161 '--output-vtt' ,
6262 action = 'store_true' ,
6363 help = 'check to output result in a vtt file' )
64-
65- parser .add_argument (
66- '-su' ,
67- '--speed-up' ,
68- action = 'store_true' ,
69- help = 'check to speed up audio by factor of 2 (faster processing, reduced accuracy)' )
70-
64+
7165 parser .add_argument (
7266 '--speed-up2' ,
7367 action = 'store' ,
@@ -126,10 +120,6 @@ def main():
126120 else :
127121 arg_out_vtt = ""
128122
129- if args .speed_up == True :
130- arg_speed = "--speed-up"
131- else :
132- arg_speed = ""
133123
134124#check if ffmpeg speedup was selected. If true, disable txt and vtt output
135125#and disable whispercpp internal speed up.
@@ -139,13 +129,20 @@ def main():
139129 arg_speed = ""
140130 arg_out_srt = "--output-srt"
141131
132+ # Split the input filename and extension
133+ input_basename , _ = os .path .splitext (os .path .basename (args .file ))
134+
135+ # Construct new output filenames based on input filename
136+ output_wav = f"{ input_basename } .wav"
137+ output_srt = f"{ input_basename } .wav.srt"
138+ output_fixed_srt = f"{ input_basename } _fixed.srt"
142139
143140#first we process the input file with ffmpeg
144141#here we construct the command line for ffmpeg and apply the FFMPEG speedup IF selected
145142 if float (args .speed_up2 ) != 1.0 :
146- cmd = f"ffmpeg.exe -y -i \" { args .file } \" -ar 16000 -ac 1 -c:a pcm_s16le -af atempo={ args .speed_up2 } output.wav "
143+ cmd = f"ffmpeg.exe -y -i \" { args .file } \" -ar 16000 -ac 1 -c:a pcm_s16le -af atempo={ args .speed_up2 } { output_wav } "
147144 else :
148- cmd = f"ffmpeg.exe -y -i \" { args .file } \" -ar 16000 -ac 1 -c:a pcm_s16le output.wav "
145+ cmd = f"ffmpeg.exe -y -i \" { args .file } \" -ar 16000 -ac 1 -c:a pcm_s16le { output_wav } "
149146
150147 if args .shell == True :
151148 #here we call the program with extra parameters to capture ffmpeg output
@@ -171,7 +168,7 @@ def main():
171168
172169#here we run whisperCPP
173170#here we construct the command line for whisperCPP
174- cmd = f"main.exe -f output.wav -m { args .model } -l { args .language } { arg_translate } { arg_out_txt } { arg_out_srt } { arg_out_vtt } { arg_speed } { args .others } "
171+ cmd = f"main.exe -f { output_wav } -m { args .model } -l { args .language } { arg_translate } { arg_out_txt } { arg_out_srt } { arg_out_vtt } { args .others } "
175172
176173
177174 if args .shell == True :
@@ -200,7 +197,7 @@ def main():
200197
201198 if float (args .speed_up2 ) != 1.0 :
202199 speedup_factor = float (args .speed_up2 ) # assign the speedup factor
203- with open ("output.wav.srt" , "r" ) as file : # Open the input SRT file
200+ with open (output_srt , "r" ) as file : # Open the input SRT file
204201 content = file .read ()
205202 file .close ()
206203 matches = re .findall (r"\d{2}:\d{2}:\d{2},\d{3}" , content ) # Use regular expressions to match timestamps in the SRT file
@@ -218,11 +215,11 @@ def main():
218215 new_milliseconds = f'{ int (((total_milliseconds % 3600000 ) % 60000 ) % 1000 ):03d} '
219216 new_time = f"{ new_hours } :{ new_minutes } :{ new_seconds } ,{ new_milliseconds } "
220217 content = content .replace (match , new_time )
221- with open ("output-fix.wav.srt" , "w" ) as file : # Write the adjusted SRT file to the output file
218+ with open (output_fixed_srt , "w" ) as file : # Write the adjusted SRT file to the output file
222219 file .write (content )
223220 file .close ()
224- os .remove ("output.wav.srt" ) #remove output.srt temporary file
221+ os .remove (output_srt ) #remove output.srt temporary file
225222#end of section that fixes the timestamps
226223
227224#remove output.wav temporary file created by ffmpeg
228- os .remove ("output.wav" )
225+ os .remove (output_wav )
0 commit comments