diff --git a/backend/transcript/views.py b/backend/transcript/views.py index abbbcd00..6af29c51 100644 --- a/backend/transcript/views.py +++ b/backend/transcript/views.py @@ -181,10 +181,16 @@ def export_transcript(request): if "text" in segment.keys(): lines.append(str(index + 1)) lines.append(segment["start_time"] + " --> " + segment["end_time"]) - if len(segment.get("speaker_id", "")) > 0 and with_speaker_info: - lines.append(segment["speaker_id"] + ": " + segment["text"] + "\n") + if "verbatim_text" in segment.keys(): + if len(segment.get("speaker_id", "")) > 0 and with_speaker_info: + lines.append(segment["speaker_id"] + ": " + segment["verbatim_text"] + "\n") + else: + lines.append(segment["verbatim_text"] + "\n") else: - lines.append(segment["text"] + "\n") + if len(segment.get("speaker_id", "")) > 0 and with_speaker_info: + lines.append(segment["speaker_id"] + ": " + segment["text"] + "\n") + else: + lines.append(segment["text"] + "\n") filename = "transcript.srt" content = "\n".join(lines) elif export_type == "vtt": @@ -193,22 +199,34 @@ def export_transcript(request): if "text" in segment.keys(): lines.append(str(index + 1)) lines.append(segment["start_time"] + " --> " + segment["end_time"]) - if len(segment.get("speaker_id", "")) > 0 and with_speaker_info: - lines.append(segment["speaker_id"] + ": " + segment["text"] + "\n") + if "verbatim_text" in segment.keys(): + if len(segment.get("speaker_id", "")) > 0 and with_speaker_info: + lines.append(segment["speaker_id"] + ": " + segment["verbatim_text"] + "\n") + else: + lines.append(segment["verbatim_text"] + "\n") else: - lines.append(segment["text"] + "\n") + if len(segment.get("speaker_id", "")) > 0 and with_speaker_info: + lines.append(segment["speaker_id"] + ": " + segment["text"] + "\n") + else: + lines.append(segment["text"] + "\n") filename = "transcript.vtt" content = "\n".join(lines) elif export_type == "txt": for index, segment in enumerate(payload): if "text" in segment.keys(): - lines.append(segment["text"]) + if "verbatim_text" in segment.keys(): + lines.append(segment["verbatim_text"]) + else: + lines.append(segment["text"]) filename = "transcript.txt" content = convert_to_paragraph(lines, task.video.name) elif export_type == "docx": for index, segment in enumerate(payload): if "text" in segment.keys(): - lines.append(segment["text"]) + if "verbatim_text" in segment.keys(): + lines.append(segment["verbatim_text"]) + else: + lines.append(segment["text"]) filename = "transcript.txt" content = convert_to_paragraph(lines, task.video.name) return convert_to_docx(content) @@ -257,31 +275,54 @@ def export_transcript(request): elif export_type == "sbv": for index, segment in enumerate(payload): - lines.append( - segment["start_time"] - + "," - + segment["end_time"] - + "\n" - + segment["text"] - + "\n" - ) + if "verbatim_text" in segment.keys(): + lines.append( + segment["start_time"] + + "," + + segment["end_time"] + + "\n" + + segment["verbatim_text"] + + "\n" + ) + else: + lines.append( + segment["start_time"] + + "," + + segment["end_time"] + + "\n" + + segment["text"] + + "\n" + ) filename = "transcript.sbv" content = "\n".join(lines) elif export_type == "TTML": lines = generate_ttml(payload) for index, segment in enumerate(payload): - lines.append( - "\t\t\t
"
- + segment["text"].replace(",", "
")
- + "
"
+ + segment["verbatim_text"].replace(",", "
")
+ + "
"
+ + segment["text"].replace(",", "
")
+ + "