able to re-transcribe
This commit is contained in:
@ -55,6 +55,13 @@ class ExportRequest(BaseModel):
|
||||
deleted_indices: Optional[List[int]] = None
|
||||
|
||||
|
||||
class TranscriptExportRequest(BaseModel):
|
||||
words: List[ExportWordModel]
|
||||
deleted_indices: Optional[List[int]] = None
|
||||
output_path: str
|
||||
format: str = "txt" # "txt" or "srt"
|
||||
|
||||
|
||||
def _map_ranges_to_output_timeline(
|
||||
ranges: List[dict],
|
||||
keep_segments: List[dict],
|
||||
@ -234,3 +241,34 @@ async def export_video(req: ExportRequest):
|
||||
except Exception as e:
|
||||
logger.error(f"Export error: {e}", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.post("/export/transcript")
|
||||
async def export_transcript(req: TranscriptExportRequest):
|
||||
"""Export transcript as plain text or SRT without rendering video."""
|
||||
try:
|
||||
from services.caption_generator import generate_srt
|
||||
|
||||
deleted_set = set(req.deleted_indices or [])
|
||||
word_dicts = [w.model_dump() for w in req.words]
|
||||
|
||||
if req.format == "srt":
|
||||
content = generate_srt(word_dicts, deleted_set)
|
||||
else:
|
||||
# Plain text: join non-deleted words
|
||||
active_words = []
|
||||
for i, w in enumerate(word_dicts):
|
||||
if i not in deleted_set:
|
||||
active_words.append(w["word"])
|
||||
content = " ".join(active_words)
|
||||
|
||||
os.makedirs(os.path.dirname(req.output_path) or ".", exist_ok=True)
|
||||
with open(req.output_path, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
|
||||
logger.info("Transcript exported to %s (format=%s)", req.output_path, req.format)
|
||||
return {"status": "ok", "output_path": req.output_path}
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Transcript export failed: {e}", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
Reference in New Issue
Block a user