{
  "openapi": "3.1.0",
  "info": {
    "title": "fxai-svc 音色转换服务",
    "version": "1.0",
    "description": "SVC / RVC 音色转换服务：人声分离 → 音色转换 → 等响混音，另含音色训练。\n基址默认 http://127.0.0.1:8187，无鉴权，响应统一 UTF-8。\n失败包络：{\"success\": false, \"ok\": false, \"error\": \"<中文原因>\"}。\n"
  },
  "servers": [
    {
      "url": "http://127.0.0.1:8187",
      "description": "本机"
    }
  ],
  "tags": [
    {
      "name": "status",
      "description": "服务状态与显存"
    },
    {
      "name": "convert",
      "description": "音色转换"
    },
    {
      "name": "assets",
      "description": "原曲素材库（已上传的原曲，可重复调用）"
    },
    {
      "name": "library",
      "description": "作品库"
    },
    {
      "name": "train",
      "description": "音色训练"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "status"
        ],
        "summary": "服务状态",
        "description": "模型未装载时不加载 torch，可高频轮询。",
        "operationId": "health",
        "responses": {
          "200": {
            "description": "服务在线",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "service",
                    "ok",
                    "state"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "healthy"
                    },
                    "service": {
                      "type": "string",
                      "const": "fxai-svc"
                    },
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "state": {
                      "type": "string",
                      "enum": [
                        "idle",
                        "loading",
                        "converting",
                        "training"
                      ]
                    },
                    "busy": {
                      "type": "boolean"
                    },
                    "in_flight": {
                      "type": "integer"
                    },
                    "queued": {
                      "type": "integer"
                    },
                    "model_loaded": {
                      "type": "boolean"
                    },
                    "loaded_voice": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "device": {
                      "type": "string"
                    },
                    "gpu": {
                      "type": "string"
                    },
                    "vram_mb": {
                      "type": "integer"
                    },
                    "voices": {
                      "type": "integer"
                    },
                    "idle_timeout": {
                      "type": "integer",
                      "description": "秒，0 表示常驻"
                    },
                    "last_use": {
                      "type": "number",
                      "description": "Unix 秒"
                    },
                    "sep_backend": {
                      "type": "string",
                      "enum": [
                        "melband",
                        "skill"
                      ]
                    },
                    "comfy": {
                      "type": "object",
                      "properties": {
                        "up": {
                          "type": [
                            "boolean",
                            "null"
                          ]
                        },
                        "url": {
                          "type": "string"
                        }
                      }
                    },
                    "separator": {
                      "type": "object",
                      "additionalProperties": true,
                      "properties": {
                        "backend": {
                          "type": "string"
                        },
                        "ready": {
                          "type": "boolean"
                        },
                        "model": {
                          "type": "string"
                        },
                        "size_mb": {
                          "type": "number"
                        },
                        "loaded": {
                          "type": "boolean"
                        },
                        "device": {
                          "type": "string"
                        },
                        "error": {
                          "type": "string"
                        }
                      }
                    },
                    "training": {
                      "type": "object",
                      "properties": {
                        "active": {
                          "type": "boolean"
                        },
                        "queued": {
                          "type": "integer"
                        },
                        "current": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "progress": {
                          "type": "number"
                        },
                        "name": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/assets": {
      "get": {
        "tags": [
          "assets"
        ],
        "summary": "已上传原曲列表",
        "description": "服务端每次收原曲都会入库，这里按「最近使用」倒序返回，供页面直接挑一条重跑。\n指向的文件已被删掉的条目会自动摘除，不会出现在列表里。\n",
        "operationId": "listAssets",
        "responses": {
          "200": {
            "description": "素材列表",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "assets"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "total": {
                      "type": "integer"
                    },
                    "total_mb": {
                      "type": "number"
                    },
                    "assets": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Asset"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/assets/scan": {
      "post": {
        "tags": [
          "assets"
        ],
        "summary": "把 input 根目录散落的音频收进素材库",
        "description": "兜底接口。手动拷进 input/ 的老文件、或入库失败留下的文件，扫一遍收编。",
        "operationId": "scanAssets",
        "responses": {
          "200": {
            "description": "扫描结果，added 是本次新收编的条数",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "total_mb": {
                      "type": "number"
                    },
                    "added": {
                      "type": "integer"
                    },
                    "assets": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Asset"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/api/assets/clear": {
      "post": {
        "tags": [
          "assets"
        ],
        "summary": "清空素材库",
        "description": "已产出任务目录里的源副本是硬链接，这里删掉不影响已有成品。",
        "operationId": "clearAssets",
        "responses": {
          "200": {
            "description": "清空结果",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "deleted": {
                      "type": "integer"
                    },
                    "freed_mb": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/assets/{id}": {
      "delete": {
        "tags": [
          "assets"
        ],
        "summary": "删一条原曲",
        "operationId": "deleteAsset",
        "parameters": [
          {
            "$ref": "#/components/parameters/AssetId"
          }
        ],
        "responses": {
          "200": {
            "description": "删除结果",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "deleted": {
                      "type": "string"
                    },
                    "freed_mb": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/api/assets/{id}/file": {
      "get": {
        "tags": [
          "assets"
        ],
        "summary": "取原曲文件",
        "description": "支持 Range 分片，浏览器可直接当 `<audio src>` 用。",
        "operationId": "getAssetFile",
        "parameters": [
          {
            "$ref": "#/components/parameters/AssetId"
          },
          {
            "name": "dl",
            "in": "query",
            "description": "带任意值即加 Content-Disposition 下载头",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "音频流",
            "content": {
              "audio/*": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "206": {
            "description": "分片",
            "content": {
              "audio/*": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/assets/{id}/rename": {
      "post": {
        "tags": [
          "assets"
        ],
        "summary": "原曲改名",
        "description": "只改显示名，不碰磁盘文件；原名后缀自动补回。",
        "operationId": "renameAsset",
        "parameters": [
          {
            "$ref": "#/components/parameters/AssetId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 120
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "改后的条目",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Asset"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/voices": {
      "get": {
        "tags": [
          "status"
        ],
        "summary": "音色列表",
        "operationId": "listVoices",
        "responses": {
          "200": {
            "description": "按 created 倒序",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "voices"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "dir": {
                      "type": "string"
                    },
                    "engine": {
                      "$ref": "#/components/schemas/EngineState"
                    },
                    "voices": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Voice"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/convert": {
      "post": {
        "tags": [
          "convert"
        ],
        "summary": "提交换声任务",
        "description": "落盘源文件后立即返回 202，任务串行排队执行。参数越界按服务端上限夹取。",
        "operationId": "createConvertJob",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "voice"
                ],
                "description": "原曲二选一：`file`（现场上传，服务端顺手入库）或 `asset_id`（引用素材库里\n已上传过的文件，不重复走网络）。两个都不给返回 400；两个都给以 `asset_id` 为准。\n",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "原曲 / 干声 / 视频，单文件 ≤200MB。与 asset_id 二选一"
                  },
                  "asset_id": {
                    "type": "string",
                    "pattern": "^u\\d{8}-\\d{4}[a-z0-9]{4}$",
                    "description": "素材库条目 id，从 GET /api/assets 取。与 file 二选一"
                  },
                  "voice": {
                    "type": "string",
                    "description": "音色 id 或中文显示名"
                  },
                  "pitch": {
                    "type": "integer",
                    "default": 0,
                    "minimum": -24,
                    "maximum": 24
                  },
                  "index_rate": {
                    "type": "number",
                    "default": 0.5,
                    "minimum": 0,
                    "maximum": 1
                  },
                  "protect": {
                    "type": "number",
                    "default": 0.33,
                    "minimum": 0,
                    "maximum": 0.5
                  },
                  "volume_envelope": {
                    "type": "number",
                    "default": 0.25,
                    "minimum": 0,
                    "maximum": 1
                  },
                  "f0_method": {
                    "type": "string",
                    "default": "rmvpe",
                    "enum": [
                      "rmvpe",
                      "fcpe"
                    ]
                  },
                  "sep_backend": {
                    "type": "string",
                    "enum": [
                      "melband",
                      "skill"
                    ],
                    "description": "取值不认识时回落默认值，不报错"
                  },
                  "inst_gain": {
                    "type": "number",
                    "default": 0,
                    "minimum": -24,
                    "maximum": 24
                  },
                  "vocal_only": {
                    "type": "string",
                    "default": "0",
                    "enum": [
                      "0",
                      "1",
                      "true",
                      "false",
                      "yes",
                      "on"
                    ]
                  },
                  "save": {
                    "type": "string",
                    "default": "1",
                    "enum": [
                      "0",
                      "1",
                      "true",
                      "false",
                      "yes",
                      "on"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "已入队",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "job"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "queued_ahead": {
                      "type": "integer"
                    },
                    "job": {
                      "$ref": "#/components/schemas/Job"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMedia"
          }
        }
      }
    },
    "/api/job/{id}": {
      "get": {
        "tags": [
          "convert"
        ],
        "summary": "单任务进度",
        "operationId": "getJob",
        "parameters": [
          {
            "$ref": "#/components/parameters/JobId"
          }
        ],
        "responses": {
          "200": {
            "description": "运行中读内存态，结束后回落 meta.json",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "job"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "job": {
                      "$ref": "#/components/schemas/Job"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/job/{id}/cancel": {
      "post": {
        "tags": [
          "convert"
        ],
        "summary": "取消转换",
        "description": "排队中立即出队；运行中在当前阶段收尾时中断。",
        "operationId": "cancelJob",
        "parameters": [
          {
            "$ref": "#/components/parameters/JobId"
          }
        ],
        "responses": {
          "200": {
            "description": "已受理",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "canceling",
                        "canceled",
                        "done",
                        "error"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/jobs": {
      "get": {
        "tags": [
          "library"
        ],
        "summary": "作品库列表",
        "description": "只列 save=1 的成果，按 created 倒序。",
        "operationId": "listJobs",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 200,
              "minimum": 1,
              "maximum": 1000
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0,
              "minimum": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "分页列表",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "total",
                    "jobs"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "total": {
                      "type": "integer"
                    },
                    "jobs": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Job"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/jobs/{id}": {
      "get": {
        "tags": [
          "library"
        ],
        "summary": "单条作品元信息",
        "operationId": "getSavedJob",
        "parameters": [
          {
            "$ref": "#/components/parameters/JobId"
          }
        ],
        "responses": {
          "200": {
            "description": "元信息",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "job": {
                      "$ref": "#/components/schemas/Job"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "library"
        ],
        "summary": "删除单条作品",
        "description": "运行中的任务转取消并保留目录，返回 404。",
        "operationId": "deleteJob",
        "parameters": [
          {
            "$ref": "#/components/parameters/JobId"
          }
        ],
        "responses": {
          "200": {
            "description": "已删除",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "deleted": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/jobs/clear": {
      "post": {
        "tags": [
          "library"
        ],
        "summary": "清空作品库",
        "operationId": "clearJobs",
        "responses": {
          "200": {
            "description": "已清空",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "deleted": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/jobs/{id}/file/{name}": {
      "get": {
        "tags": [
          "library"
        ],
        "summary": "下载成品或原曲",
        "description": "支持 Range 分段（206）。name 含 /、\\、.. 或超 200 字符返回 400。",
        "operationId": "downloadJobFile",
        "parameters": [
          {
            "$ref": "#/components/parameters/JobId"
          },
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "任务目录下的文件名，允许中文"
          },
          {
            "name": "dl",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "1",
                "true",
                "yes"
              ]
            },
            "description": "给定值时按附件下载，文件名还原原曲名"
          }
        ],
        "responses": {
          "200": {
            "description": "全量内容",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "206": {
            "description": "分段内容",
            "headers": {
              "Content-Range": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/load": {
      "post": {
        "tags": [
          "status"
        ],
        "summary": "手动装载模型",
        "operationId": "loadModel",
        "parameters": [
          {
            "name": "voice",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "省略则只导入引擎，不装具体音色"
          }
        ],
        "responses": {
          "200": {
            "description": "装载后的完整状态体",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "500": {
            "description": "装载失败",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/unload": {
      "post": {
        "tags": [
          "status"
        ],
        "summary": "释放显存",
        "description": "卸载换声模型与分离模型，转换进行中返回 409。",
        "operationId": "unloadModels",
        "responses": {
          "200": {
            "description": "状态体 + released",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "released": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "转换中",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/train/jobs": {
      "get": {
        "tags": [
          "train"
        ],
        "summary": "训练任务列表",
        "operationId": "listTrainJobs",
        "responses": {
          "200": {
            "description": "列表 + 底模状态 + 下载进度",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "jobs": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TrainJob"
                      }
                    },
                    "pretrained": {
                      "$ref": "#/components/schemas/Pretrained"
                    },
                    "download": {
                      "$ref": "#/components/schemas/Download"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/train": {
      "post": {
        "tags": [
          "train"
        ],
        "summary": "建训练任务",
        "description": "训练跑在独立子进程，HTTP 服务只读 state.json。",
        "operationId": "createTrainJob",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "音色显示名"
                  },
                  "epochs": {
                    "type": "integer",
                    "default": 250
                  },
                  "batch": {
                    "type": "integer",
                    "default": 8
                  },
                  "sr": {
                    "type": "integer",
                    "default": 40000
                  },
                  "file": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    },
                    "description": "素材音频，可多文件；单次总量 ≤600MB"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "已建任务",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "job": {
                      "$ref": "#/components/schemas/TrainJob"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "409": {
            "description": "转换中或任务重名",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        }
      }
    },
    "/api/train/job/{id}": {
      "get": {
        "tags": [
          "train"
        ],
        "summary": "训练进度",
        "operationId": "getTrainJob",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "任务 + 底模状态",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "job": {
                      "$ref": "#/components/schemas/TrainJob"
                    },
                    "pretrained": {
                      "$ref": "#/components/schemas/Pretrained"
                    },
                    "download": {
                      "$ref": "#/components/schemas/Download"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/train/job/{id}/cancel": {
      "post": {
        "tags": [
          "train"
        ],
        "summary": "取消训练",
        "description": "写 cancel.flag，子进程在下一个检查点退出。",
        "operationId": "cancelTrainJob",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "已受理",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "const": true
                    },
                    "job": {
                      "$ref": "#/components/schemas/TrainJob"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/train/pretrained": {
      "get": {
        "tags": [
          "train"
        ],
        "summary": "底模状态",
        "operationId": "getPretrained",
        "responses": {
          "200": {
            "description": "是否就绪",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "pretrained": {
                      "$ref": "#/components/schemas/Pretrained"
                    },
                    "download": {
                      "$ref": "#/components/schemas/Download"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "train"
        ],
        "summary": "下载训练底模",
        "description": "只下 40k 的 G/D 两件，hf-mirror 优先。",
        "operationId": "downloadPretrained",
        "responses": {
          "200": {
            "description": "已开始",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "started": {
                      "type": "boolean",
                      "const": true
                    },
                    "download": {
                      "$ref": "#/components/schemas/Download"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "JobId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^\\d{8}-\\d{4}-[a-z0-9]{4}$"
        },
        "description": "任务 / 成果 ID，格式 YYYYMMDD-HHMM-xxxx"
      },
      "AssetId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^u\\d{8}-\\d{4}[a-z0-9]{4}$"
        },
        "description": "原曲素材 ID，格式 uYYYYMMDD-HHMMxxxx"
      }
    },
    "responses": {
      "BadRequest": {
        "description": "请求非法",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "不存在",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "TooLarge": {
        "description": "体积超限",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "UnsupportedMedia": {
        "description": "扩展名不支持",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "success",
          "error"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "const": false
          },
          "ok": {
            "type": "boolean",
            "const": false
          },
          "error": {
            "type": "string"
          }
        }
      },
      "EngineState": {
        "type": "object",
        "properties": {
          "ready": {
            "type": "boolean"
          },
          "device": {
            "type": "string"
          },
          "voice": {
            "type": [
              "string",
              "null"
            ]
          },
          "last_use": {
            "type": "number"
          }
        }
      },
      "Voice": {
        "type": "object",
        "required": [
          "id",
          "name",
          "has_index"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "提交任务用 ASCII id"
          },
          "name": {
            "type": "string",
            "description": "显示名，可为中文"
          },
          "size_mb": {
            "type": "number"
          },
          "has_index": {
            "type": "boolean"
          },
          "index": {
            "type": "string"
          },
          "created": {
            "type": [
              "string",
              "null"
            ]
          },
          "epoch": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "Asset": {
        "type": "object",
        "required": [
          "id",
          "name",
          "url"
        ],
        "description": "已上传的原曲条目。列表按 last_used 倒序，最近用过的排最前",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^u\\d{8}-\\d{4}[a-z0-9]{4}$"
          },
          "name": {
            "type": "string"
          },
          "ext": {
            "type": "string",
            "example": ".wav"
          },
          "size": {
            "type": "integer"
          },
          "size_mb": {
            "type": "number"
          },
          "duration": {
            "type": "number",
            "description": "秒"
          },
          "created": {
            "type": "integer"
          },
          "last_used": {
            "type": "integer"
          },
          "used": {
            "type": "integer",
            "description": "被引用次数"
          },
          "url": {
            "type": "string",
            "description": "播放地址，相对服务根"
          },
          "url_dl": {
            "type": "string",
            "description": "带下载头的地址"
          }
        }
      },
      "JobParams": {
        "type": "object",
        "properties": {
          "voice": {
            "type": "string"
          },
          "pitch": {
            "type": "integer"
          },
          "index_rate": {
            "type": "number"
          },
          "protect": {
            "type": "number"
          },
          "volume_envelope": {
            "type": "number"
          },
          "f0_method": {
            "type": "string"
          },
          "sep_backend": {
            "type": "string"
          },
          "inst_gain": {
            "type": "number"
          },
          "vocal_only": {
            "type": "boolean"
          }
        }
      },
      "Job": {
        "type": "object",
        "required": [
          "id",
          "status",
          "stage",
          "progress"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "done",
              "error",
              "canceled"
            ]
          },
          "stage": {
            "type": "string",
            "enum": [
              "queued",
              "loading",
              "separate",
              "convert",
              "mix",
              "done",
              "error",
              "canceled"
            ]
          },
          "stage_text": {
            "type": "string"
          },
          "progress": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "params": {
            "$ref": "#/components/schemas/JobParams"
          },
          "saved": {
            "type": "boolean"
          },
          "created": {
            "type": "number"
          },
          "elapsed": {
            "type": [
              "number",
              "null"
            ]
          },
          "duration": {
            "type": "number",
            "description": "原曲秒数"
          },
          "sep": {
            "type": "string",
            "enum": [
              "melband",
              "skill",
              "skip",
              ""
            ]
          },
          "result": {
            "type": "string"
          },
          "result_url": {
            "type": "string"
          },
          "source_url": {
            "type": "string"
          },
          "size_mb": {
            "type": "number"
          }
        }
      },
      "TrainJob": {
        "type": "object",
        "required": [
          "id",
          "status",
          "progress"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "done",
              "error",
              "canceled"
            ]
          },
          "stage": {
            "type": "string"
          },
          "stage_text": {
            "type": "string"
          },
          "progress": {
            "type": "number"
          },
          "epoch": {
            "type": "integer"
          },
          "epochs": {
            "type": "integer"
          },
          "minutes": {
            "type": "number"
          },
          "slices": {
            "type": "integer"
          },
          "elapsed": {
            "type": "number"
          },
          "eta": {
            "type": [
              "integer",
              "null"
            ]
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "result": {
            "type": [
              "object",
              "null"
            ]
          },
          "created": {
            "type": "number"
          },
          "log": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Pretrained": {
        "type": "object",
        "properties": {
          "ready": {
            "type": "boolean"
          },
          "missing": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Download": {
        "type": "object",
        "properties": {
          "running": {
            "type": "boolean"
          },
          "done": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "message": {
            "type": "string"
          },
          "speed": {
            "type": "string"
          }
        }
      }
    }
  }
}