7550559aa0
- 删除8个未使用IPC命令,保留validate_media_path - file.rs返回类型优化为ApiResponse<()> - point_service.consume()注释与签名一致 - VideoGeneration改为拼接成功后扣费 - 添加漏扣费风险注释 - 删除过时测试文件 - 修复camelToSnake连续大写字母问题 - vidu.py import移至模块顶层 Refs: P1-1~P1-6 技术债务清理
91 lines
2.4 KiB
Python
91 lines
2.4 KiB
Python
"""
|
|
火山引擎音视频字幕 API 路由
|
|
============================
|
|
|
|
提供自动字幕打轴功能。
|
|
"""
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter, HTTPException, Request
|
|
|
|
from app.core.exceptions import PlatformError
|
|
from app.schemas.caption import (
|
|
AutoAlignSubmitRequest,
|
|
)
|
|
from app.schemas.common import ApiResponse, success_response
|
|
from app.services.volcengine_caption_service import (
|
|
VolcengineCaptionService,
|
|
get_caption_service,
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
router = APIRouter(prefix="/caption", tags=["Caption"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post("/ata/align")
|
|
async def auto_align_caption(request_body: AutoAlignSubmitRequest, request: Request, max_wait_time: int = 120):
|
|
"""
|
|
自动字幕打轴(完整流程)
|
|
|
|
提交打轴任务并轮询结果,直接返回最终数据。
|
|
"""
|
|
try:
|
|
logger.info(f"[Caption API] Auto align request: audio_url={request_body.audio_url[:50]}...")
|
|
service = await get_caption_service(request)
|
|
result = await service.auto_align_caption(
|
|
audio_url=request_body.audio_url,
|
|
audio_text=request_body.audio_text,
|
|
caption_type=request_body.caption_type,
|
|
sta_punc_mode=request_body.sta_punc_mode,
|
|
max_wait_time=max_wait_time,
|
|
)
|
|
logger.info(
|
|
f"[Caption API] Auto align result: utterances_count={len(result.utterances) if result.utterances else 0}"
|
|
)
|
|
if result.utterances:
|
|
logger.info(f"[Caption API] First utterance: {result.utterances[0]}")
|
|
|
|
# 手动序列化为字典,确保嵌套模型正确处理
|
|
response_data = {
|
|
"code": 0,
|
|
"message": "Success",
|
|
"duration": result.duration,
|
|
"utterances": [
|
|
{
|
|
"text": u.text,
|
|
"start_time": u.start_time,
|
|
"end_time": u.end_time,
|
|
}
|
|
for u in (result.utterances or [])
|
|
],
|
|
}
|
|
logger.info(f"[Caption API] Response data: {response_data}")
|
|
return success_response(data=response_data)
|
|
|
|
except PlatformError as e:
|
|
logger.error(f"自动打轴失败: {e}")
|
|
raise
|
|
except Exception as e:
|
|
logger.error(f"自动打轴异常: {e}")
|
|
raise HTTPException(status_code=500, detail="字幕打轴失败,请稍后重试")
|
|
|
|
|
|
|
|
|
|
|
|
|