137137 "castilian" : "es" ,
138138}
139139
140- whisper_langs = sorted (LANGUAGES .keys ()) + sorted (
141- [k .title () for k in TO_LANGUAGE_CODE .keys ()]
142- )
140+ whisper_langs = sorted (LANGUAGES .keys ()) + sorted ([k .title () for k in TO_LANGUAGE_CODE .keys ()])
143141
144142langs_to_iso = {
145143 "af" : "afr" ,
@@ -270,19 +268,15 @@ def get_words_speaker_mapping(wrd_ts, spk_ts, word_anchor_option="start"):
270268 s , e , sp = spk_ts [turn_idx ]
271269 if turn_idx == len (spk_ts ) - 1 :
272270 e = get_word_ts_anchor (ws , we , option = "end" )
273- wrd_spk_mapping .append (
274- {"word" : wrd , "start_time" : ws , "end_time" : we , "speaker" : sp }
275- )
271+ wrd_spk_mapping .append ({"word" : wrd , "start_time" : ws , "end_time" : we , "speaker" : sp })
276272 return wrd_spk_mapping
277273
278274
279275sentence_ending_punctuations = ".?!"
280276
281277
282278def get_first_word_idx_of_sentence (word_idx , word_list , speaker_list , max_words ):
283- is_word_sentence_end = (
284- lambda x : x >= 0 and word_list [x ][- 1 ] in sentence_ending_punctuations
285- )
279+ is_word_sentence_end = lambda x : x >= 0 and word_list [x ][- 1 ] in sentence_ending_punctuations
286280 left_idx = word_idx
287281 while (
288282 left_idx > 0
@@ -296,9 +290,7 @@ def get_first_word_idx_of_sentence(word_idx, word_list, speaker_list, max_words)
296290
297291
298292def get_last_word_idx_of_sentence (word_idx , word_list , max_words ):
299- is_word_sentence_end = (
300- lambda x : x >= 0 and word_list [x ][- 1 ] in sentence_ending_punctuations
301- )
293+ is_word_sentence_end = lambda x : x >= 0 and word_list [x ][- 1 ] in sentence_ending_punctuations
302294 right_idx = word_idx
303295 while (
304296 right_idx < len (word_list ) - 1
@@ -307,19 +299,12 @@ def get_last_word_idx_of_sentence(word_idx, word_list, max_words):
307299 ):
308300 right_idx += 1
309301
310- return (
311- right_idx
312- if right_idx == len (word_list ) - 1 or is_word_sentence_end (right_idx )
313- else - 1
314- )
302+ return right_idx if right_idx == len (word_list ) - 1 or is_word_sentence_end (right_idx ) else - 1
315303
316304
317- def get_realigned_ws_mapping_with_punctuation (
318- word_speaker_mapping , max_words_in_sentence = 50
319- ):
305+ def get_realigned_ws_mapping_with_punctuation (word_speaker_mapping , max_words_in_sentence = 50 ):
320306 is_word_sentence_end = (
321- lambda x : x >= 0
322- and word_speaker_mapping [x ]["word" ][- 1 ] in sentence_ending_punctuations
307+ lambda x : x >= 0 and word_speaker_mapping [x ]["word" ][- 1 ] in sentence_ending_punctuations
323308 )
324309 wsp_len = len (word_speaker_mapping )
325310
@@ -357,9 +342,7 @@ def get_realigned_ws_mapping_with_punctuation(
357342 k += 1
358343 continue
359344
360- speaker_list [left_idx : right_idx + 1 ] = [mod_speaker ] * (
361- right_idx - left_idx + 1
362- )
345+ speaker_list [left_idx : right_idx + 1 ] = [mod_speaker ] * (right_idx - left_idx + 1 )
363346 k = right_idx
364347
365348 k += 1
@@ -434,9 +417,7 @@ def format_timestamp(
434417 milliseconds -= seconds * 1_000
435418
436419 hours_marker = f"{ hours :02d} :" if always_include_hours or hours > 0 else ""
437- return (
438- f"{ hours_marker } { minutes :02d} :{ seconds :02d} { decimal_marker } { milliseconds :03d} "
439- )
420+ return f"{ hours_marker } { minutes :02d} :{ seconds :02d} { decimal_marker } { milliseconds :03d} "
440421
441422
442423def write_srt (transcript , file ):
@@ -490,17 +471,11 @@ def _get_next_start_timestamp(word_timestamps, current_word_index, final_timesta
490471 return word_timestamps [next_word_index ]["start" ]
491472
492473
493- def filter_missing_timestamps (
494- word_timestamps , initial_timestamp = 0 , final_timestamp = None
495- ):
474+ def filter_missing_timestamps (word_timestamps , initial_timestamp = 0 , final_timestamp = None ):
496475 # handle the first and last word
497476 if word_timestamps [0 ].get ("start" ) is None :
498- word_timestamps [0 ]["start" ] = (
499- initial_timestamp if initial_timestamp is not None else 0
500- )
501- word_timestamps [0 ]["end" ] = _get_next_start_timestamp (
502- word_timestamps , 0 , final_timestamp
503- )
477+ word_timestamps [0 ]["start" ] = initial_timestamp if initial_timestamp is not None else 0
478+ word_timestamps [0 ]["end" ] = _get_next_start_timestamp (word_timestamps , 0 , final_timestamp )
504479
505480 result = [
506481 word_timestamps [0 ],
0 commit comments