@@ -561,7 +561,7 @@ class BatchRecognizer(object):
561561
562562#============================================================== APP PARTS ==============================================================#
563563
564- VERSION = '0.1.13 '
564+ VERSION = '0.1.14 '
565565
566566arraylist_models = []
567567arraylist_models .append ("ca-es" );
@@ -1836,6 +1836,8 @@ def vosk_transcribe(src, dst, video_filepath, subtitle_format):
18361836
18371837 regions = []
18381838 transcriptions = []
1839+ created_regions = []
1840+ created_subtitles = []
18391841 translated_transcriptions = []
18401842
18411843 if not_transcribing : return
@@ -1941,8 +1943,6 @@ def vosk_transcribe(src, dst, video_filepath, subtitle_format):
19411943
19421944 if not_transcribing : return
19431945
1944- created_regions = []
1945- created_subtitles = []
19461946 for entry in timed_subtitles :
19471947 created_regions .append (entry [0 ])
19481948 created_subtitles .append (entry [1 ])
@@ -3296,89 +3296,105 @@ def main():
32963296
32973297 elif event == '-EVENT-SAVE-RECORDED-STREAMING-' :
32983298
3299- if not args .video_filename :
3300- tmp_recorded_streaming_filename = "record.mp4"
3301- else :
3302- tmp_recorded_streaming_filename = args .video_filename
3299+ if not recognizing :
33033300
3304- tmp_recorded_streaming_filepath = os .path .join (tempfile .gettempdir (), tmp_recorded_streaming_filename )
3301+ if not args .video_filename :
3302+ tmp_recorded_streaming_filename = "record.mp4"
3303+ else :
3304+ tmp_recorded_streaming_filename = args .video_filename
33053305
3306- if os .path .isfile ( tmp_recorded_streaming_filepath ):
3306+ tmp_recorded_streaming_filepath = os .path .join ( tempfile . gettempdir (), tmp_recorded_streaming_filename )
33073307
3308- saved_recorded_streaming_filename = sg . popup_get_file ( '' , no_window = True , save_as = True , font = FONT , default_path = saved_recorded_streaming_filename , file_types = video_file_types )
3308+ if os . path . isfile ( tmp_recorded_streaming_filepath ):
33093309
3310- if saved_recorded_streaming_filename :
3311- shutil .copy (tmp_recorded_streaming_filepath , saved_recorded_streaming_filename )
3310+ saved_recorded_streaming_filename = sg .popup_get_file ('' , no_window = True , save_as = True , font = FONT , default_path = saved_recorded_streaming_filename , file_types = video_file_types )
3311+
3312+ if saved_recorded_streaming_filename :
3313+ shutil .copy (tmp_recorded_streaming_filepath , saved_recorded_streaming_filename )
3314+
3315+ else :
3316+ FONT = ("Helvetica" , 10 )
3317+ sg .set_options (font = FONT )
3318+ sg .Popup ("No streaming was recorded" , title = "Info" , line_width = 50 )
33123319
33133320 else :
3314- FONT = ("Helvetica" , 10 )
3315- sg .set_options (font = FONT )
3316- sg .Popup ("No streaming was recorded" , title = "Info" , line_width = 50 )
3321+ pass
33173322
33183323
33193324 elif event == '-EVENT-SAVE-SRC-TRANSCRIPTION-' :
3320- if os .path .isfile (tmp_src_txt_transcription_filepath ):
33213325
3322- saved_src_subtitle_filename = sg . popup_get_file ( '' , no_window = True , save_as = True , font = FONT , file_types = subtitle_file_types )
3326+ if not recognizing :
33233327
3324- if saved_src_subtitle_filename :
3328+ if os . path . isfile ( tmp_src_txt_transcription_filepath ) :
33253329
3326- selected_subtitle_format = saved_src_subtitle_filename . split ( '.' )[ - 1 ]
3330+ saved_src_subtitle_filename = sg . popup_get_file ( '' , no_window = True , save_as = True , font = FONT , file_types = subtitle_file_types )
33273331
3328- if selected_subtitle_format in FORMATTERS .keys ():
3329- timed_subtitles = [(r , t ) for r , t in zip (regions , transcriptions ) if t ]
3330- subtitle_format = selected_subtitle_format
3331- formatter = FORMATTERS .get (subtitle_format )
3332- formatted_subtitles = formatter (timed_subtitles )
3333- tmp_src_subtitle_filename = saved_src_subtitle_filename
3334- subtitle_file = open (tmp_src_subtitle_filename , 'wb' )
3335- subtitle_file .write (formatted_subtitles .encode ("utf-8" ))
3336- subtitle_file .close ()
3337- else :
3338- saved_src_subtitle_file = open (saved_src_subtitle_filename , "w" )
3339- tmp_src_txt_transcription_file = open (tmp_src_txt_transcription_filepath , "r" )
3340- for line in tmp_src_txt_transcription_file :
3341- if line :
3342- saved_src_subtitle_file .write (line )
3343- saved_src_subtitle_file .close ()
3344- tmp_src_txt_transcription_file .close ()
3332+ if saved_src_subtitle_filename :
3333+
3334+ selected_subtitle_format = saved_src_subtitle_filename .split ('.' )[- 1 ]
3335+
3336+ if selected_subtitle_format in FORMATTERS .keys ():
3337+ timed_subtitles = [(r , t ) for r , t in zip (regions , transcriptions ) if t ]
3338+ subtitle_format = selected_subtitle_format
3339+ formatter = FORMATTERS .get (subtitle_format )
3340+ formatted_subtitles = formatter (timed_subtitles )
3341+ tmp_src_subtitle_filename = saved_src_subtitle_filename
3342+ subtitle_file = open (tmp_src_subtitle_filename , 'wb' )
3343+ subtitle_file .write (formatted_subtitles .encode ("utf-8" ))
3344+ subtitle_file .close ()
3345+ else :
3346+ saved_src_subtitle_file = open (saved_src_subtitle_filename , "w" )
3347+ tmp_src_txt_transcription_file = open (tmp_src_txt_transcription_filepath , "r" )
3348+ for line in tmp_src_txt_transcription_file :
3349+ if line :
3350+ saved_src_subtitle_file .write (line )
3351+ saved_src_subtitle_file .close ()
3352+ tmp_src_txt_transcription_file .close ()
3353+
3354+ else :
3355+ FONT = ("Helvetica" , 10 )
3356+ sg .set_options (font = FONT )
3357+ sg .Popup ("No transcriptions was recorded" , title = "Info" , line_width = 50 )
33453358
33463359 else :
3347- FONT = ("Helvetica" , 10 )
3348- sg .set_options (font = FONT )
3349- sg .Popup ("No transcriptions was recorded" , title = "Info" , line_width = 50 )
3360+ pass
33503361
33513362
33523363 elif event == '-EVENT-SAVE-DST-TRANSCRIPTION-' :
33533364
3354- if os . path . isfile ( tmp_dst_txt_transcription_filepath ) :
3365+ if not recognizing :
33553366
3356- saved_dst_subtitle_filename = sg . popup_get_file ( '' , no_window = True , save_as = True , font = FONT , file_types = subtitle_file_types )
3367+ if os . path . isfile ( tmp_dst_txt_transcription_filepath ):
33573368
3358- if saved_dst_subtitle_filename :
3369+ saved_dst_subtitle_filename = sg . popup_get_file ( '' , no_window = True , save_as = True , font = FONT , file_types = subtitle_file_types )
33593370
3360- selected_subtitle_format = saved_dst_subtitle_filename .split ('.' )[- 1 ]
3371+ if saved_dst_subtitle_filename :
3372+
3373+ selected_subtitle_format = saved_dst_subtitle_filename .split ('.' )[- 1 ]
3374+
3375+ if selected_subtitle_format in FORMATTERS .keys ():
3376+ timed_translated_subtitles = [(r , t ) for r , t in zip (created_regions , translated_transcriptions ) if t ]
3377+ subtitle_format = selected_subtitle_format
3378+ formatter = FORMATTERS .get (subtitle_format )
3379+ formatted_translated_subtitles = formatter (timed_translated_subtitles )
3380+ saved_dst_subtitle_file = open (saved_dst_subtitle_filename , 'wb' )
3381+ saved_dst_subtitle_file .write (formatted_translated_subtitles .encode ("utf-8" ))
3382+ saved_dst_subtitle_file .close ()
3383+ else :
3384+ saved_dst_subtitle_file = open (saved_dst_subtitle_filename , "w" )
3385+ tmp_dst_txt_transcription_file = open (tmp_dst_txt_transcription_filepath , "r" )
3386+ for line in tmp_dst_txt_transcription_file :
3387+ if line :
3388+ saved_dst_subtitle_file .write (line )
3389+ saved_dst_subtitle_file .close ()
3390+ tmp_dst_txt_transcription_file .close ()
3391+ else :
3392+ FONT = ("Helvetica" , 10 )
3393+ sg .set_options (font = FONT )
3394+ sg .Popup ("No translated transcriptions was recorded" , title = "Info" , line_width = 50 )
33613395
3362- if selected_subtitle_format in FORMATTERS .keys ():
3363- timed_translated_subtitles = [(r , t ) for r , t in zip (created_regions , translated_transcriptions ) if t ]
3364- subtitle_format = selected_subtitle_format
3365- formatter = FORMATTERS .get (subtitle_format )
3366- formatted_translated_subtitles = formatter (timed_translated_subtitles )
3367- saved_dst_subtitle_file = open (saved_dst_subtitle_filename , 'wb' )
3368- saved_dst_subtitle_file .write (formatted_translated_subtitles .encode ("utf-8" ))
3369- saved_dst_subtitle_file .close ()
3370- else :
3371- saved_dst_subtitle_file = open (saved_dst_subtitle_filename , "w" )
3372- tmp_dst_txt_transcription_file = open (tmp_dst_txt_transcription_filepath , "r" )
3373- for line in tmp_dst_txt_transcription_file :
3374- if line :
3375- saved_dst_subtitle_file .write (line )
3376- saved_dst_subtitle_file .close ()
3377- tmp_dst_txt_transcription_file .close ()
33783396 else :
3379- FONT = ("Helvetica" , 10 )
3380- sg .set_options (font = FONT )
3381- sg .Popup ("No translated transcriptions was recorded" , title = "Info" , line_width = 50 )
3397+ pass
33823398
33833399
33843400 elif event == '-EXCEPTION-' :
0 commit comments