# 说话人分离转录

> 音频生成

上传音频文件进行说话人分离转录。

**端点**: `POST https://api.modelverse.cn/v1/audio/transcriptions`

**Content-Type**: `multipart/form-data`

**认证方式**: `Authorization: Bearer {api_key}`

## 接口说明

这是一个标准的 HTTP RESTful API 接口，用于音频文件的说话人分离转录。

### 请求方式
- **方法**: POST
- **Content-Type**: `multipart/form-data`
- **认证**: `Authorization: Bearer {api_key}`

## 请求地址

`POST https://api.modelverse.cn/v1/audio/transcriptions`

## 请求体

## 响应

- **200** — 转录成功
- **400** — 请求参数错误
- **401** — 认证失败
- **500** — 服务器内部错误

## OpenAPI 定义

```json
{
  "openapi": "3.1.0",
  "x-language": "zh-CN",
  "info": {
    "title": "GPT-4o Transcribe Diarize 说话人分离转录模型接口文档",
    "version": "1.0.0",
    "description": "这是 ModelVerse 上 GPT-4o Transcribe Diarize 说话人分离转录模型的接口文档。\n\n接口协议为 HTTP POST，端点为 `https://api.modelverse.cn/v1/audio/transcriptions`。\n\n**特点**：说话人分离转录，上传音频文件，返回带 speaker 标签的转录结果。\n"
  },
  "servers": [
    {
      "url": "https://api.modelverse.cn",
      "description": "ModelVerse API endpoint"
    }
  ],
  "tags": [
    {
      "name": "GPT-4o-Transcribe-Diarize",
      "description": "GPT-4o Transcribe Diarize 说话人分离转录模型，支持音频文件上传，返回带说话人标签的转录结果。"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/audio/transcriptions": {
      "post": {
        "summary": "说话人分离转录",
        "description": "上传音频文件进行说话人分离转录。\n\n**端点**: `POST https://api.modelverse.cn/v1/audio/transcriptions`\n\n**Content-Type**: `multipart/form-data`\n\n**认证方式**: `Authorization: Bearer {api_key}`\n\n## 接口说明\n\n这是一个标准的 HTTP RESTful API 接口，用于音频文件的说话人分离转录。\n\n### 请求方式\n- **方法**: POST\n- **Content-Type**: `multipart/form-data`\n- **认证**: `Authorization: Bearer {api_key}`\n",
        "operationId": "createTranscription",
        "tags": [
          "GPT-4o-Transcribe-Diarize"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "file"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "const": "gpt-4o-transcribe-diarize",
                    "description": "模型名称，固定为 gpt-4o-transcribe-diarize"
                  },
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "音频文件（支持 flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm 格式）"
                  },
                  "response_format": {
                    "type": "string",
                    "enum": [
                      "json",
                      "diarized_json"
                    ],
                    "default": "diarized_json",
                    "description": "响应格式，推荐使用 diarized_json 以获取说话人信息"
                  },
                  "language": {
                    "type": "string",
                    "description": "音频语言代码（ISO-639-1），如 zh、en",
                    "example": "zh"
                  },
                  "temperature": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1,
                    "default": 0,
                    "description": "采样温度"
                  }
                }
              },
              "examples": {
                "diarizedRequest": {
                  "summary": "说话人分离转录请求",
                  "value": {
                    "model": "gpt-4o-transcribe-diarize",
                    "file": "@audio.mp3",
                    "response_format": "diarized_json",
                    "language": "zh"
                  }
                },
                "simpleRequest": {
                  "summary": "简单转录请求",
                  "value": {
                    "model": "gpt-4o-transcribe-diarize",
                    "file": "@audio.mp3",
                    "response_format": "json"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "转录成功",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/DiarizedTranscriptionResponse"
                    },
                    {
                      "$ref": "#/components/schemas/SimpleTranscriptionResponse"
                    }
                  ]
                },
                "examples": {
                  "diarizedResponse": {
                    "summary": "说话人分离响应",
                    "value": {
                      "text": "你好，我是小明。你好，我是小红。",
                      "segments": [
                        {
                          "type": "transcript.text.segment",
                          "text": "你好，我是小明。",
                          "speaker": "A",
                          "start": 0,
                          "end": 2.5,
                          "id": "seg_0"
                        },
                        {
                          "type": "transcript.text.segment",
                          "text": "你好，我是小红。",
                          "speaker": "B",
                          "start": 2.8,
                          "end": 5.2,
                          "id": "seg_1"
                        }
                      ],
                      "usage": {
                        "type": "tokens",
                        "total_tokens": 796,
                        "input_tokens": 216,
                        "input_token_details": {
                          "text_tokens": 0,
                          "audio_tokens": 216
                        },
                        "output_tokens": 580
                      }
                    }
                  },
                  "simpleResponse": {
                    "summary": "简单转录响应",
                    "value": {
                      "text": "你好，我是小明。你好，我是小红。",
                      "usage": {
                        "type": "tokens",
                        "total_tokens": 796,
                        "input_tokens": 216,
                        "input_token_details": {
                          "text_tokens": 0,
                          "audio_tokens": 216
                        },
                        "output_tokens": 580
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "请求参数错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": {
                    "message": "Invalid file format",
                    "type": "invalid_request_error",
                    "param": "file",
                    "code": "invalid_file_format"
                  }
                }
              }
            }
          },
          "401": {
            "description": "认证失败",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": {
                    "message": "Invalid API key",
                    "type": "authentication_error",
                    "code": "invalid_api_key"
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务器内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": {
                    "message": "Internal server error",
                    "type": "server_error",
                    "code": "internal_error"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key",
        "description": "在请求 Header 中传入 ModelVerse API Key（`Authorization: Bearer <api_key>`）。\n"
      }
    },
    "schemas": {
      "DiarizedTranscriptionResponse": {
        "type": "object",
        "description": "说话人分离转录响应",
        "required": [
          "text",
          "segments",
          "usage"
        ],
        "properties": {
          "text": {
            "type": "string",
            "description": "完整转录文本",
            "example": "你好，我是小明。你好，我是小红。"
          },
          "segments": {
            "type": "array",
            "description": "分段转录结果（含说话人信息）",
            "items": {
              "$ref": "#/components/schemas/TranscriptSegment"
            }
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        }
      },
      "SimpleTranscriptionResponse": {
        "type": "object",
        "description": "简单转录响应（无说话人信息）",
        "required": [
          "text",
          "usage"
        ],
        "properties": {
          "text": {
            "type": "string",
            "description": "完整转录文本",
            "example": "你好，我是小明。你好，我是小红。"
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        }
      },
      "TranscriptSegment": {
        "type": "object",
        "description": "转录片段",
        "required": [
          "type",
          "text",
          "speaker",
          "start",
          "end",
          "id"
        ],
        "properties": {
          "type": {
            "type": "string",
            "const": "transcript.text.segment",
            "description": "片段类型"
          },
          "text": {
            "type": "string",
            "description": "转录文本",
            "example": "你好，我是小明。"
          },
          "speaker": {
            "type": "string",
            "description": "说话人标识",
            "example": "A"
          },
          "start": {
            "type": "number",
            "description": "开始时间（秒）",
            "example": 0
          },
          "end": {
            "type": "number",
            "description": "结束时间（秒）",
            "example": 2.5
          },
          "id": {
            "type": "string",
            "description": "片段 ID",
            "example": "seg_0"
          }
        }
      },
      "Usage": {
        "type": "object",
        "description": "用量信息",
        "required": [
          "type",
          "total_tokens",
          "input_tokens",
          "output_tokens"
        ],
        "properties": {
          "type": {
            "type": "string",
            "const": "tokens",
            "description": "用量类型"
          },
          "total_tokens": {
            "type": "integer",
            "description": "总 Token 数",
            "example": 796
          },
          "input_tokens": {
            "type": "integer",
            "description": "输入 Token 数",
            "example": 216
          },
          "input_token_details": {
            "type": "object",
            "description": "输入 Token 详情",
            "properties": {
              "text_tokens": {
                "type": "integer",
                "description": "文本 Token 数",
                "example": 0
              },
              "audio_tokens": {
                "type": "integer",
                "description": "音频 Token 数",
                "example": 216
              }
            }
          },
          "output_tokens": {
            "type": "integer",
            "description": "输出 Token 数",
            "example": 580
          }
        }
      },
      "Error": {
        "type": "object",
        "description": "错误响应",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "message",
              "type"
            ],
            "properties": {
              "message": {
                "type": "string",
                "description": "错误消息"
              },
              "type": {
                "type": "string",
                "description": "错误类型"
              },
              "param": {
                "type": "string",
                "description": "相关参数"
              },
              "code": {
                "type": "string",
                "description": "错误代码"
              }
            }
          }
        }
      }
    },
    "examples": {
      "CurlExample": {
        "summary": "cURL 请求示例",
        "description": "使用 cURL 调用说话人分离转录接口",
        "value": "curl -X POST https://api.modelverse.cn/v1/audio/transcriptions \\\n  -H \"Authorization: Bearer $TOKEN\" \\\n  -F \"model=gpt-4o-transcribe-diarize\" \\\n  -F \"file=@audio.mp3\" \\\n  -F \"response_format=diarized_json\" \\\n  -F \"language=zh\" \\\n  -F \"diarize=true\"\n"
      },
      "PythonExample": {
        "summary": "Python 请求示例",
        "description": "使用 Python requests 调用说话人分离转录接口",
        "value": "import requests\n\nurl = \"https://api.modelverse.cn/v1/audio/transcriptions\"\nheaders = {\"Authorization\": \"Bearer your-token\"}\nfiles = {\"file\": open(\"audio.mp3\", \"rb\")}\ndata = {\n    \"model\": \"gpt-4o-transcribe-diarize\",\n    \"response_format\": \"diarized_json\",\n    \"language\": \"zh\",\n    \"diarize\": \"true\"\n}\n\nresponse = requests.post(url, headers=headers, files=files, data=data)\nresult = response.json()\n\nprint(\"转录文本:\", result[\"text\"])\nprint(\"说话人分离:\")\nfor segment in result[\"segments\"]:\n    print(f\"[{segment['speaker']}] {segment['text']}\")\nprint(\"用量:\", result[\"usage\"])\n"
      },
      "NodeExample": {
        "summary": "Node.js 请求示例",
        "description": "使用 Node.js axios 调用说话人分离转录接口",
        "value": "const axios = require('axios');\nconst FormData = require('form-data');\nconst fs = require('fs');\n\nconst form = new FormData();\nform.append('model', 'gpt-4o-transcribe-diarize');\nform.append('file', fs.createReadStream('audio.mp3'));\nform.append('response_format', 'diarized_json');\nform.append('language', 'zh');\nform.append('diarize', 'true');\n\nconst response = await axios.post(\n  'https://api.modelverse.cn/v1/audio/transcriptions',\n  form,\n  {\n    headers: {\n      ...form.getHeaders(),\n      'Authorization': 'Bearer your-token'\n    }\n  }\n);\n\nconsole.log('转录文本:', response.data.text);\nconsole.log('说话人分离:', response.data.segments);\nconsole.log('用量:', response.data.usage);\n"
      }
    }
  }
}
```
