@@ -437,6 +437,8 @@ def handle_highlight(transcription_result, style_options, replace_dict, video_re
437437 words = segment .get ('words' , [])
438438 if not words :
439439 continue
440+
441+ # Process all words in the segment
440442 processed_words = []
441443 for w_info in words :
442444 w = process_subtitle_text (w_info .get ('word' , '' ), replace_dict , all_caps , 0 )
@@ -446,24 +448,42 @@ def handle_highlight(transcription_result, style_options, replace_dict, video_re
446448 if not processed_words :
447449 continue
448450
451+ # Split into lines if max_words_per_line is specified
449452 if max_words_per_line > 0 :
450453 line_sets = [processed_words [i :i + max_words_per_line ] for i in range (0 , len (processed_words ), max_words_per_line )]
451454 else :
452455 line_sets = [processed_words ]
453456
454457 for line_set in line_sets :
458+ # Get the start time of the first word and end time of the last word
459+ line_start = line_set [0 ][1 ]
460+ line_end = line_set [- 1 ][2 ]
461+
462+ # Create a persistent line that stays visible during the entire segment
463+ base_text = ' ' .join (word for word , _ , _ in line_set )
464+ start_time = format_ass_time (line_start )
465+ end_time = format_ass_time (line_end )
466+ position_tag = f"{{\\ an{ an_code } \\ pos({ final_x } ,{ final_y } )}}"
467+ events .append (f"Dialogue: 0,{ start_time } ,{ end_time } ,Default,,0,0,0,,{ position_tag } {{\\ c{ line_color } }}{ base_text } " )
468+
469+ # Add individual highlighting for each word
455470 for idx , (word , w_start , w_end ) in enumerate (line_set ):
456- line_words = []
457- for w_idx , (w_text , _ , _ ) in enumerate (line_set ):
458- if w_idx == idx :
459- line_words .append (f"{{\\ c{ word_color } }}{ w_text } {{\\ c{ line_color } }}" )
471+ # Create the highlighted version of this word within the line
472+ highlighted_words = []
473+
474+ for i , (w , _ , _ ) in enumerate (line_set ):
475+ if i == idx :
476+ # This is the current word - highlight it
477+ highlighted_words .append (f"{{\\ c{ word_color } }}{ w } {{\\ c{ line_color } }}" )
460478 else :
461- line_words .append (w_text )
462- full_text = ' ' .join (line_words )
463- start_time = format_ass_time (w_start )
464- end_time = format_ass_time (w_end )
465- position_tag = f"{{\\ an{ an_code } \\ pos({ final_x } ,{ final_y } )}}"
466- events .append (f"Dialogue: 0,{ start_time } ,{ end_time } ,Default,,0,0,0,,{ position_tag } {{\\ c{ line_color } }}{ full_text } " )
479+ # Add the word without highlighting
480+ highlighted_words .append (w )
481+
482+ highlighted_text = ' ' .join (highlighted_words )
483+ word_start_time = format_ass_time (w_start )
484+ word_end_time = format_ass_time (w_end )
485+ events .append (f"Dialogue: 1,{ word_start_time } ,{ word_end_time } ,Default,,0,0,0,,{ position_tag } {{\\ c{ line_color } }}{ highlighted_text } " )
486+
467487 logger .info (f"Handled { len (events )} dialogues in highlight style." )
468488 return "\n " .join (events )
469489
0 commit comments