Files
audio2text/app/models/task.py
zikai 00e2a95fb7 Initial commit: audio2text 双语字幕生成服务
- 音频/视频转双语(英/中)SRT 字幕,Docker 容器化,CPU 开发/GPU 生产同一份代码
- faster-whisper ASR(词级时间戳) + 断句时间戳重算 + NLLB 翻译(模型不共驻)
- 分片上传(断点续传) + SQLite 持久化 + 主页/历史/日志页面
- 历史页文件名搜索;缓存定时清理(默认保留7天,可配置)
- 双 Dockerfile(cpu/gpu) + setup/start/stop 脚本
2026-07-06 06:54:19 +00:00

41 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Task ORM一个上传完成的视频对应一个转写任务承载状态机。"""
from __future__ import annotations
from datetime import datetime, timezone
from sqlalchemy import DateTime, Float, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from ..database import Base
def _now() -> datetime:
return datetime.now(timezone.utc)
class Task(Base):
__tablename__ = "task"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
# 原始视频文件名(用户上传时的名字)
filename: Mapped[str] = mapped_column(String(512), nullable=False)
# 视频在 upload_dir 下的相对路径(提取音频前后可能被删)
source_path: Mapped[str] = mapped_column(String(1024), nullable=False)
# 状态机queued → extracting → transcribing → segmenting → translating → done | failed
status: Mapped[str] = mapped_column(String(32), nullable=False, default="queued")
# 0-100 进度
progress: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
# 失败原因
error: Mapped[str | None] = mapped_column(Text, nullable=True)
# 输出字幕路径(双语合并 / 英文 / 中文)
bilingual_srt_path: Mapped[str | None] = mapped_column(String(1024), nullable=True)
en_srt_path: Mapped[str | None] = mapped_column(String(1024), nullable=True)
zh_srt_path: Mapped[str | None] = mapped_column(String(1024), nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=_now)
updated_at: Mapped[datetime] = mapped_column(DateTime, default=_now, onupdate=_now)
def __repr__(self) -> str:
return f"<Task id={self.id} {self.filename} status={self.status}>"