Show timestamp and speaker name on same line as text in transcript .docx
This commit is contained in:
+14
-12
@@ -328,19 +328,21 @@ def create_transcript_docx(text: str, filename: str):
|
||||
m = re.match(r"\[(\d+:\d+(?::\d+)?)\]\s*(.+?):\s*(.*)", line)
|
||||
if m:
|
||||
ts, speaker, content = m.groups()
|
||||
# Speaker line: bold, underlined, indented
|
||||
p_spk = doc.add_paragraph()
|
||||
p_spk.paragraph_format.left_indent = Inches(0.25)
|
||||
run_spk = p_spk.add_run(f"[{ts}] {speaker.upper()}")
|
||||
run_spk.bold = True
|
||||
run_spk.underline = True
|
||||
run_spk.font.name = "Courier"
|
||||
run_spk.font.size = Pt(12)
|
||||
# Single paragraph: [timestamp] SPEAKER NAME underlined, then text inline
|
||||
p = doc.add_paragraph()
|
||||
p.paragraph_format.left_indent = Inches(0.25)
|
||||
|
||||
# Spoken text line: further indented
|
||||
p_txt = doc.add_paragraph()
|
||||
p_txt.paragraph_format.left_indent = Inches(0.5)
|
||||
run_txt = p_txt.add_run(content.strip())
|
||||
# Timestamp + speaker name (underline only, not bold)
|
||||
run_label = p.add_run(f"[{ts}] {speaker.upper()}: ")
|
||||
run_label.bold = False
|
||||
run_label.underline = True
|
||||
run_label.font.name = "Courier"
|
||||
run_label.font.size = Pt(12)
|
||||
|
||||
# Spoken text (no underline, no bold)
|
||||
run_txt = p.add_run(content.strip())
|
||||
run_txt.bold = False
|
||||
run_txt.underline = False
|
||||
run_txt.font.name = "Courier"
|
||||
run_txt.font.size = Pt(12)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user