@@ -77,21 +77,34 @@ def make_test_case(args, npy_savename, sync_was_successful):
7777
7878def try_sync (args , reference_pipe , srt_pipes , result ):
7979 sync_was_successful = True
80+ exc = None
8081 try :
81- logger .info ('extracting speech segments from subtitles file %s...' , args .srtin )
82+ logger .info ('extracting speech segments from %s...' ,
83+ 'stdin' if args .srtin is None else 'subtitles file {}' .format (args .srtin ))
8284 for srt_pipe in srt_pipes :
83- srt_pipe .fit (args .srtin )
85+ if callable (srt_pipe ):
86+ continue
87+ else :
88+ srt_pipe .fit (args .srtin )
8489 logger .info ('...done' )
8590 logger .info ('computing alignments...' )
86- offset_samples , best_srt_pipe = MaxScoreAligner (
87- FFTAligner , SAMPLE_RATE , args .max_offset_seconds
88- ).fit_transform (
89- reference_pipe .transform (args .reference ),
90- srt_pipes ,
91- )
91+ if args .skip_sync :
92+ best_score = 0.
93+ best_srt_pipe = srt_pipes [0 ]
94+ if callable (best_srt_pipe ):
95+ best_srt_pipe = best_srt_pipe (1.0 ).fit (args .srtin )
96+ offset_samples = 0
97+ else :
98+ (best_score , offset_samples ), best_srt_pipe = MaxScoreAligner (
99+ FFTAligner , args .srtin , SAMPLE_RATE , args .max_offset_seconds
100+ ).fit_transform (
101+ reference_pipe .transform (args .reference ),
102+ srt_pipes ,
103+ )
92104 logger .info ('...done' )
93105 offset_seconds = offset_samples / float (SAMPLE_RATE )
94106 scale_step = best_srt_pipe .named_steps ['scale' ]
107+ logger .info ('score: %.3f' , best_score )
95108 logger .info ('offset seconds: %.3f' , offset_seconds )
96109 logger .info ('framerate scale factor: %.3f' , scale_step .scale_factor )
97110 output_steps = [('shift' , SubtitleShifter (offset_seconds ))]
@@ -109,10 +122,16 @@ def try_sync(args, reference_pipe, srt_pipes, result):
109122 except FailedToFindAlignmentException as e :
110123 sync_was_successful = False
111124 logger .error (e )
125+ except Exception as e :
126+ exc = e
127+ sync_was_successful = False
128+ logger .error (e )
112129 else :
113130 result ['offset_seconds' ] = offset_seconds
114131 result ['framerate_scale_factor' ] = scale_step .scale_factor
115132 finally :
133+ if exc is not None :
134+ raise exc
116135 result ['sync_was_successful' ] = sync_was_successful
117136 return sync_was_successful
118137
@@ -158,10 +177,16 @@ def make_srt_pipes(args):
158177 if args .no_fix_framerate :
159178 framerate_ratios = [1. ]
160179 else :
161- framerate_ratios = np .concatenate ([
180+ framerate_ratios = list ( np .concatenate ([
162181 [1. ], np .array (FRAMERATE_RATIOS ), 1. / np .array (FRAMERATE_RATIOS )
163- ])
164- parser = make_subtitle_parser (fmt = os .path .splitext (args .srtin )[- 1 ][1 :], caching = True , ** args .__dict__ )
182+ ]))
183+ if args .gss :
184+ framerate_ratios .append (None )
185+ if args .srtin is None :
186+ srtin_format = 'srt'
187+ else :
188+ srtin_format = os .path .splitext (args .srtin )[- 1 ][1 :]
189+ parser = make_subtitle_parser (fmt = srtin_format , caching = True , ** args .__dict__ )
165190 srt_pipes = [
166191 make_subtitle_speech_pipeline (
167192 ** override (args , scale_factor = scale_factor , parser = parser )
@@ -226,12 +251,13 @@ def validate_args(args):
226251
227252
228253def validate_file_permissions (args ):
254+ error_string_template = 'unable to {action} {file}; try ensuring file exists and has correct permissions'
229255 if not os .access (args .reference , os .R_OK ):
230- raise ValueError ('unable to read reference %s (try checking permissions)' % args .reference )
231- if not os .access (args .srtin , os .R_OK ):
232- raise ValueError ('unable to read input subtitles %s (try checking permissions)' % args .srtin )
233- if os .path .exists (args .srtout ) and not os .access (args .srtout , os .W_OK ):
234- raise ValueError ('unable to write output subtitles %s (try checking permissions)' % args .srtout )
256+ raise ValueError (error_string_template . format ( action = ' read reference' , file = args .reference ) )
257+ if args . srtin is not None and not os .access (args .srtin , os .R_OK ):
258+ raise ValueError (error_string_template . format ( action = ' read input subtitles' , file = args .srtin ) )
259+ if args . srtout is not None and os .path .exists (args .srtout ) and not os .access (args .srtout , os .W_OK ):
260+ raise ValueError (error_string_template . format ( action = ' write output subtitles' , file = args .srtout ) )
235261 if args .make_test_case or args .serialize_speech :
236262 npy_savename = os .path .splitext (args .reference )[0 ] + '.npz'
237263 if os .path .exists (npy_savename ) and not os .access (npy_savename , os .W_OK ):
@@ -340,7 +366,7 @@ def add_cli_only_args(parser):
340366 parser .add_argument ('--start-seconds' , type = int , default = DEFAULT_START_SECONDS ,
341367 help = 'Start time for processing '
342368 '(default=%d seconds).' % DEFAULT_START_SECONDS )
343- parser .add_argument ('--max-offset-seconds' , type = int , default = DEFAULT_MAX_OFFSET_SECONDS ,
369+ parser .add_argument ('--max-offset-seconds' , type = float , default = DEFAULT_MAX_OFFSET_SECONDS ,
344370 help = 'The max allowed offset seconds for any subtitle segment '
345371 '(default=%d seconds).' % DEFAULT_MAX_OFFSET_SECONDS )
346372 parser .add_argument ('--frame-rate' , type = int , default = DEFAULT_FRAME_RATE ,
@@ -372,6 +398,8 @@ def add_cli_only_args(parser):
372398 'directory).' )
373399 parser .add_argument ('--vlc-mode' , action = 'store_true' , help = argparse .SUPPRESS )
374400 parser .add_argument ('--gui-mode' , action = 'store_true' , help = argparse .SUPPRESS )
401+ parser .add_argument ('--skip-sync' , action = 'store_true' , help = argparse .SUPPRESS )
402+ parser .add_argument ('--gss' , action = 'store_true' , help = argparse .SUPPRESS )
375403
376404
377405def make_parser ():
0 commit comments