【剪映小助手】字幕信息生成接口(Caption Infos)

字幕信息生成接口

目录

简介

字幕信息生成接口:说明该接口在草稿自动化里的用途、依赖模块与常见报错。具体方法、路径、字段和校验请以 OpenAPI 为准。

依赖关系分析

组件依赖图

#mermaid-svg-PM1tfhvoUEcoHTeY{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-PM1tfhvoUEcoHTeY .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-PM1tfhvoUEcoHTeY .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-PM1tfhvoUEcoHTeY .error-icon{fill:#552222;}#mermaid-svg-PM1tfhvoUEcoHTeY .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-PM1tfhvoUEcoHTeY .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-PM1tfhvoUEcoHTeY .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-PM1tfhvoUEcoHTeY .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-PM1tfhvoUEcoHTeY .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-PM1tfhvoUEcoHTeY .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-PM1tfhvoUEcoHTeY .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-PM1tfhvoUEcoHTeY .marker{fill:#333333;stroke:#333333;}#mermaid-svg-PM1tfhvoUEcoHTeY .marker.cross{stroke:#333333;}#mermaid-svg-PM1tfhvoUEcoHTeY svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-PM1tfhvoUEcoHTeY p{margin:0;}#mermaid-svg-PM1tfhvoUEcoHTeY .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-PM1tfhvoUEcoHTeY .cluster-label text{fill:#333;}#mermaid-svg-PM1tfhvoUEcoHTeY .cluster-label span{color:#333;}#mermaid-svg-PM1tfhvoUEcoHTeY .cluster-label span p{background-color:transparent;}#mermaid-svg-PM1tfhvoUEcoHTeY .label text,#mermaid-svg-PM1tfhvoUEcoHTeY span{fill:#333;color:#333;}#mermaid-svg-PM1tfhvoUEcoHTeY .node rect,#mermaid-svg-PM1tfhvoUEcoHTeY .node circle,#mermaid-svg-PM1tfhvoUEcoHTeY .node ellipse,#mermaid-svg-PM1tfhvoUEcoHTeY .node polygon,#mermaid-svg-PM1tfhvoUEcoHTeY .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-PM1tfhvoUEcoHTeY .rough-node .label text,#mermaid-svg-PM1tfhvoUEcoHTeY .node .label text,#mermaid-svg-PM1tfhvoUEcoHTeY .image-shape .label,#mermaid-svg-PM1tfhvoUEcoHTeY .icon-shape .label{text-anchor:middle;}#mermaid-svg-PM1tfhvoUEcoHTeY .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-PM1tfhvoUEcoHTeY .rough-node .label,#mermaid-svg-PM1tfhvoUEcoHTeY .node .label,#mermaid-svg-PM1tfhvoUEcoHTeY .image-shape .label,#mermaid-svg-PM1tfhvoUEcoHTeY .icon-shape .label{text-align:center;}#mermaid-svg-PM1tfhvoUEcoHTeY .node.clickable{cursor:pointer;}#mermaid-svg-PM1tfhvoUEcoHTeY .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-PM1tfhvoUEcoHTeY .arrowheadPath{fill:#333333;}#mermaid-svg-PM1tfhvoUEcoHTeY .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-PM1tfhvoUEcoHTeY .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-PM1tfhvoUEcoHTeY .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-PM1tfhvoUEcoHTeY .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-PM1tfhvoUEcoHTeY .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-PM1tfhvoUEcoHTeY .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-PM1tfhvoUEcoHTeY .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-PM1tfhvoUEcoHTeY .cluster text{fill:#333;}#mermaid-svg-PM1tfhvoUEcoHTeY .cluster span{color:#333;}#mermaid-svg-PM1tfhvoUEcoHTeY div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-PM1tfhvoUEcoHTeY .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-PM1tfhvoUEcoHTeY rect.text{fill:none;stroke-width:0;}#mermaid-svg-PM1tfhvoUEcoHTeY .icon-shape,#mermaid-svg-PM1tfhvoUEcoHTeY .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-PM1tfhvoUEcoHTeY .icon-shape p,#mermaid-svg-PM1tfhvoUEcoHTeY .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-PM1tfhvoUEcoHTeY .icon-shape .label rect,#mermaid-svg-PM1tfhvoUEcoHTeY .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-PM1tfhvoUEcoHTeY .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-PM1tfhvoUEcoHTeY .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-PM1tfhvoUEcoHTeY :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 文档模块
测试模块
内部模块
外部依赖
FastAPI
Pydantic
Uvicorn
main.py
v1.py
schemas/
service/
utils/
manual_test_caption_infos.py
单元测试
caption_infos.zh.md
openapi.yaml

数据流依赖

#mermaid-svg-XaHLFwqUt5hcDFKa{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-XaHLFwqUt5hcDFKa .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-XaHLFwqUt5hcDFKa .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-XaHLFwqUt5hcDFKa .error-icon{fill:#552222;}#mermaid-svg-XaHLFwqUt5hcDFKa .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-XaHLFwqUt5hcDFKa .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-XaHLFwqUt5hcDFKa .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-XaHLFwqUt5hcDFKa .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-XaHLFwqUt5hcDFKa .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-XaHLFwqUt5hcDFKa .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-XaHLFwqUt5hcDFKa .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-XaHLFwqUt5hcDFKa .marker{fill:#333333;stroke:#333333;}#mermaid-svg-XaHLFwqUt5hcDFKa .marker.cross{stroke:#333333;}#mermaid-svg-XaHLFwqUt5hcDFKa svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-XaHLFwqUt5hcDFKa p{margin:0;}#mermaid-svg-XaHLFwqUt5hcDFKa .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-XaHLFwqUt5hcDFKa .cluster-label text{fill:#333;}#mermaid-svg-XaHLFwqUt5hcDFKa .cluster-label span{color:#333;}#mermaid-svg-XaHLFwqUt5hcDFKa .cluster-label span p{background-color:transparent;}#mermaid-svg-XaHLFwqUt5hcDFKa .label text,#mermaid-svg-XaHLFwqUt5hcDFKa span{fill:#333;color:#333;}#mermaid-svg-XaHLFwqUt5hcDFKa .node rect,#mermaid-svg-XaHLFwqUt5hcDFKa .node circle,#mermaid-svg-XaHLFwqUt5hcDFKa .node ellipse,#mermaid-svg-XaHLFwqUt5hcDFKa .node polygon,#mermaid-svg-XaHLFwqUt5hcDFKa .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-XaHLFwqUt5hcDFKa .rough-node .label text,#mermaid-svg-XaHLFwqUt5hcDFKa .node .label text,#mermaid-svg-XaHLFwqUt5hcDFKa .image-shape .label,#mermaid-svg-XaHLFwqUt5hcDFKa .icon-shape .label{text-anchor:middle;}#mermaid-svg-XaHLFwqUt5hcDFKa .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-XaHLFwqUt5hcDFKa .rough-node .label,#mermaid-svg-XaHLFwqUt5hcDFKa .node .label,#mermaid-svg-XaHLFwqUt5hcDFKa .image-shape .label,#mermaid-svg-XaHLFwqUt5hcDFKa .icon-shape .label{text-align:center;}#mermaid-svg-XaHLFwqUt5hcDFKa .node.clickable{cursor:pointer;}#mermaid-svg-XaHLFwqUt5hcDFKa .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-XaHLFwqUt5hcDFKa .arrowheadPath{fill:#333333;}#mermaid-svg-XaHLFwqUt5hcDFKa .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-XaHLFwqUt5hcDFKa .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-XaHLFwqUt5hcDFKa .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-XaHLFwqUt5hcDFKa .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-XaHLFwqUt5hcDFKa .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-XaHLFwqUt5hcDFKa .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-XaHLFwqUt5hcDFKa .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-XaHLFwqUt5hcDFKa .cluster text{fill:#333;}#mermaid-svg-XaHLFwqUt5hcDFKa .cluster span{color:#333;}#mermaid-svg-XaHLFwqUt5hcDFKa div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-XaHLFwqUt5hcDFKa .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-XaHLFwqUt5hcDFKa rect.text{fill:none;stroke-width:0;}#mermaid-svg-XaHLFwqUt5hcDFKa .icon-shape,#mermaid-svg-XaHLFwqUt5hcDFKa .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-XaHLFwqUt5hcDFKa .icon-shape p,#mermaid-svg-XaHLFwqUt5hcDFKa .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-XaHLFwqUt5hcDFKa .icon-shape .label rect,#mermaid-svg-XaHLFwqUt5hcDFKa .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-XaHLFwqUt5hcDFKa .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-XaHLFwqUt5hcDFKa .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-XaHLFwqUt5hcDFKa :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 输出数据
处理流程
输入数据
客户端请求
JSON 数据
JSON 解析
数据验证
业务处理
序列化
HTTP 响应
JSON 响应体

性能考虑

内存使用优化

  1. 流式处理:字幕信息生成采用逐项处理的方式,避免一次性加载大量数据
  2. 内存复用:使用列表推导式和内置函数减少内存分配
  3. 字符串处理:使用高效的 JSON 序列化方法

并发处理能力

  1. 异步支持:基于 FastAPI 的异步特性,支持高并发请求
  2. 连接池:数据库连接和外部 API 调用使用连接池管理
  3. 缓存策略:对于重复的字幕信息可以考虑缓存机制

错误处理机制

  1. 参数验证:在服务层和路由层双重验证,确保数据完整性
  2. 异常捕获:统一的异常处理机制,防止服务崩溃
  3. 日志记录:详细的日志记录便于问题诊断和性能监控

故障排除指南

常见错误及解决方案

错误类型 错误代码 描述 解决方案
参数验证错误 400 texts 和 timelines 长度不匹配 确保两个数组长度相同
JSON 解析错误 400 请求体不是有效的 JSON 检查 JSON 格式和语法
时间线无效 400 start >= end 或负值 确保时间线参数有效
字体大小无效 400 font_size <= 0 使用正整数作为字体大小
关键词参数不匹配 400 keywords 长度与 texts 不匹配 确保关键词数量正确

调试技巧

  1. 启用详细日志:检查服务层的日志输出
  2. 参数验证:使用 Pydantic 的模型验证功能
  3. 单元测试:运行测试套件验证功能正确性
  4. API 文档:使用交互式 API 文档测试接口

更多信息

字段说明、校验规则与示例以 OpenAPI 为准;需要对照源码时请查看 schemas/service/ 与路由注册处。

文档信息