# 音频转写

> 音频生成

在 `generationConfig.audioTranscriptionConfig` 中配置转写参数，模型会把输入音频转写为文本。`contents[].parts[]` 中传入音频（`fileData.fileUri` 或 `inlineData`），不要传入文本提示。

转写结果位于 `candidates[].content.parts[].audioTranscription`（包含 `text`、`languageCode`、`speakerLabel`、`words` 及时间偏移），流式返回时同一字段会分片出现，可用 `finished` 判断当前片段是否结束。

**流式请求**：本文档路径为非流式接口。如需流式响应，必须将请求路径中的 `generateContent` 替换为 `streamGenerateContent`，即 `/v1beta/models/gemini-3.5-transcribe:streamGenerateContent`，请求头与请求体和非流式调用完全相同。

## 请求地址

`POST https://api.modelverse.cn/v1beta/models/gemini-3.5-transcribe:generateContent`

## 请求体

## 响应

- **200** — 转写结果。文本位于 `candidates[].content.parts[].text`，结构化转写信息位于同一 part 的 `audioTranscription`。
流式响应为 text/event-stream，每个 `data` 是一个 `GenerateContentResponse` 分片，`audioTranscription.finished` 表示当前片段是否结束。
- **4XX** — 客户端错误响应，例如参数非法、`customVocabulary` 与 `diarization` 同时指定。
- **default** — 错误响应。

## OpenAPI 定义

```json
{
  "openapi": "3.1.0",
  "x-language": "zh-CN",
  "info": {
    "title": "gemini-3.5-transcribe 音频转写",
    "version": "v1beta",
    "description": "ModelVerse 上的 Gemini 兼容同步转写接口。`gemini-3.5-transcribe` 在单次请求中转写完整的预录音频文件，单次音频时长上限 15 分钟。\n\n支持 85 种以上语言的自动检测，包括同一段音频内混用多种语言；已知语言时可通过 `generationConfig.audioTranscriptionConfig.languageCodes` 提供提示以提升准确率。\n\n转写模式由 `mode` 控制：`VERBATIM`（默认）逐字输出，保留填充词、重复、停顿和口误；`SMART` 会去除填充词与口吃、处理口头自我更正、自动分段与列表，并格式化日期、货币和数字。\n\n可选能力：`wordTimestamp` 返回字词级时间戳（实验性，会降低转写准确率）；`diarization` 区分说话人，最多 8 位（实验性）；`customVocabulary` 提供最多 1000 个自定义词汇引导识别，建议不超过 100 个。`customVocabulary` 不能与 `diarization` 或 `wordTimestamp` 同时使用，同时指定时请求会被拒绝。\n\n音频可通过 `fileData.fileUri` 传入可访问的音频文件 URL，也可通过 `inlineData` 传入 Base64 编码的音频数据（单次请求体上限约 20 MB）。转写结果位于 `candidates[].content.parts[].audioTranscription`，同时也会写入该 part 的 `text`。\n\n本文档路径为非流式接口；如需流式返回，将路径中的 `generateContent` 替换为 `streamGenerateContent`，请求头与请求体完全相同。"
  },
  "servers": [
    {
      "url": "https://api.modelverse.cn",
      "description": "中国大陆"
    },
    {
      "url": "https://api.umodelverse.ai",
      "description": "海外"
    },
    {
      "url": "https://api-us-ca.umodelverse.ai",
      "description": "美国洛杉矶"
    },
    {
      "url": "https://api-sg.umodelverse.ai",
      "description": "新加坡"
    },
    {
      "url": "https://api-ge-fra.umodelverse.ai",
      "description": "法兰克福"
    }
  ],
  "tags": [
    {
      "name": "gemini-3.5-transcribe",
      "description": "音频转写。将预录音频文件转写为文本，支持逐字与智能两种转写模式、语言自动检测、字词级时间戳、说话人区分与自定义词汇。"
    }
  ],
  "security": [
    {
      "xGoogApiKey": []
    }
  ],
  "externalDocs": {
    "description": "Gemini 3.5 Transcribe 官方文档。",
    "url": "https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/3-5-transcribe?hl=zh-cn"
  },
  "paths": {
    "/v1beta/models/gemini-3.5-transcribe:generateContent": {
      "post": {
        "tags": [
          "gemini-3.5-transcribe"
        ],
        "operationId": "generateContentGemini35TranscribeZhCN",
        "summary": "音频转写",
        "description": "在 `generationConfig.audioTranscriptionConfig` 中配置转写参数，模型会把输入音频转写为文本。`contents[].parts[]` 中传入音频（`fileData.fileUri` 或 `inlineData`），不要传入文本提示。\n\n转写结果位于 `candidates[].content.parts[].audioTranscription`（包含 `text`、`languageCode`、`speakerLabel`、`words` 及时间偏移），流式返回时同一字段会分片出现，可用 `finished` 判断当前片段是否结束。\n\n**流式请求**：本文档路径为非流式接口。如需流式响应，必须将请求路径中的 `generateContent` 替换为 `streamGenerateContent`，即 `/v1beta/models/gemini-3.5-transcribe:streamGenerateContent`，请求头与请求体和非流式调用完全相同。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerateContentRequest"
              },
              "examples": {
                "nonStreamingUrl": {
                  "summary": "音频转写 - 音频文件 URL",
                  "description": "非流式调用 `/v1beta/models/gemini-3.5-transcribe:generateContent`，音频通过可公开访问的 URL 传入。",
                  "value": {
                    "contents": [
                      {
                        "role": "user",
                        "parts": [
                          {
                            "fileData": {
                              "fileUri": "https://storage.googleapis.com/modelverse-sz-modelverse01/xxxx.mp3",
                              "mimeType": "audio/mp3"
                            }
                          }
                        ]
                      }
                    ],
                    "generationConfig": {
                      "audioTranscriptionConfig": {
                        "languageCodes": [
                          "zh-CN"
                        ]
                      }
                    }
                  }
                },
                "nonStreamingInlineData": {
                  "summary": "音频转写 - inlineData 内联音频",
                  "description": "非流式调用，音频以 Base64 编码放入 `inlineData.data`，单次请求体上限约 20 MB。",
                  "value": {
                    "contents": [
                      {
                        "role": "user",
                        "parts": [
                          {
                            "inlineData": {
                              "mimeType": "audio/mp3",
                              "data": "<AUDIO_BASE64>"
                            }
                          }
                        ]
                      }
                    ],
                    "generationConfig": {
                      "audioTranscriptionConfig": {
                        "languageCodes": [
                          "zh-CN"
                        ]
                      }
                    }
                  }
                },
                "smartModeWithTimestamps": {
                  "summary": "智能转写并返回字词级时间戳",
                  "description": "`mode: SMART` 启用智能转写，`wordTimestamp: true` 返回字词级时间戳。注意 `wordTimestamp` 为实验性能力，可能降低转写准确率，且不能与 `customVocabulary` 同时使用。",
                  "value": {
                    "contents": [
                      {
                        "role": "user",
                        "parts": [
                          {
                            "fileData": {
                              "fileUri": "https://storage.googleapis.com/modelverse-sz-modelverse01/meeting.mp3",
                              "mimeType": "audio/mp3"
                            }
                          }
                        ]
                      }
                    ],
                    "generationConfig": {
                      "audioTranscriptionConfig": {
                        "languageCodes": [
                          "zh-CN"
                        ],
                        "mode": "SMART",
                        "wordTimestamp": true
                      }
                    }
                  }
                },
                "diarization": {
                  "summary": "双人对话转写并区分说话人",
                  "description": "`diarization: true` 启用说话人区分，响应中通过 `audioTranscription.speakerLabel` 标记说话人（实验性，最多 8 位）。该能力不能与 `customVocabulary` 同时使用。",
                  "value": {
                    "contents": [
                      {
                        "role": "user",
                        "parts": [
                          {
                            "fileData": {
                              "fileUri": "https://storage.googleapis.com/modelverse-sz-modelverse01/interview.mp3",
                              "mimeType": "audio/mp3"
                            }
                          }
                        ]
                      }
                    ],
                    "generationConfig": {
                      "audioTranscriptionConfig": {
                        "languageCodes": [
                          "zh-CN"
                        ],
                        "diarization": true
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "转写结果。文本位于 `candidates[].content.parts[].text`，结构化转写信息位于同一 part 的 `audioTranscription`。\n流式响应为 text/event-stream，每个 `data` 是一个 `GenerateContentResponse` 分片，`audioTranscription.finished` 表示当前片段是否结束。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerateContentResponse"
                },
                "examples": {
                  "transcription": {
                    "summary": "非流式转写结果",
                    "value": {
                      "candidates": [
                        {
                          "content": {
                            "role": "model",
                            "parts": [
                              {
                                "text": "今天我们来讨论第三季度的目标。",
                                "audioTranscription": {
                                  "text": "今天我们来讨论第三季度的目标。",
                                  "languageCode": "zh-CN",
                                  "startOffset": "0s",
                                  "endOffset": "2.4s",
                                  "finished": true
                                }
                              }
                            ]
                          },
                          "finishReason": "STOP",
                          "index": 0
                        }
                      ],
                      "usageMetadata": {
                        "promptTokenCount": 320,
                        "candidatesTokenCount": 18,
                        "totalTokenCount": 338
                      }
                    }
                  }
                }
              }
            }
          },
          "4XX": {
            "description": "客户端错误响应，例如参数非法、`customVocabulary` 与 `diarization` 同时指定。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          },
          "default": {
            "description": "错误响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "xGoogApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-goog-api-key",
        "description": "Gemini 兼容 API Key 请求头。"
      }
    },
    "schemas": {
      "Status": {
        "type": "object",
        "description": "标准错误响应结构，包含错误码、错误消息与错误详情。",
        "properties": {
          "code": {
            "type": "integer",
            "format": "int32",
            "description": "状态码，对应 google.rpc.Code 枚举值，例如 3 表示 INVALID_ARGUMENT、8 表示 RESOURCE_EXHAUSTED。"
          },
          "message": {
            "type": "string",
            "description": "面向开发者、可读的错误消息。"
          },
          "details": {
            "type": "array",
            "description": "错误详情列表，用于携带结构化的补充信息。",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        },
        "additionalProperties": true
      },
      "GenerateContentRequest": {
        "type": "object",
        "description": "转写请求体。待转写音频放入 `contents`，转写参数放入 `generationConfig.audioTranscriptionConfig`。",
        "properties": {
          "contents": {
            "type": "array",
            "minItems": 1,
            "description": "输入内容数组。转写场景只需一个 `role: user` 的内容项，其 `parts` 中包含音频（`fileData` 或 `inlineData`），不要放入文本提示。",
            "items": {
              "$ref": "#/components/schemas/Content"
            }
          },
          "generationConfig": {
            "description": "生成配置，转写相关参数集中在 `audioTranscriptionConfig` 中。",
            "$ref": "#/components/schemas/GenerationConfig"
          }
        },
        "required": [
          "contents",
          "generationConfig"
        ]
      },
      "Content": {
        "type": "object",
        "description": "单个对话内容项。",
        "properties": {
          "role": {
            "type": "string",
            "description": "内容角色；请求中固定为 `user`，响应中为 `model`。",
            "enum": [
              "user",
              "model"
            ]
          },
          "parts": {
            "type": "array",
            "minItems": 1,
            "description": "内容片段列表。请求中为音频片段，响应中为转写文本与转写结构。",
            "items": {
              "$ref": "#/components/schemas/Part"
            }
          }
        },
        "required": [
          "parts"
        ]
      },
      "Part": {
        "type": "object",
        "description": "内容片段。请求中携带音频数据，响应中携带转写文本与 `audioTranscription`。",
        "properties": {
          "fileData": {
            "description": "通过 URL 引用的音频文件，适用于较大的音频。",
            "$ref": "#/components/schemas/FileData"
          },
          "inlineData": {
            "description": "内联音频数据，适用于较小的音频；单次请求体上限约 20 MB。",
            "$ref": "#/components/schemas/Blob"
          },
          "text": {
            "type": "string",
            "description": "文本内容。请求中不使用；响应中为转写出的文本。"
          },
          "audioTranscription": {
            "description": "仅输出。结构化转写结果，包含完整文本、语言、说话人标签与字词级时间戳。",
            "readOnly": true,
            "$ref": "#/components/schemas/Transcription"
          }
        },
        "additionalProperties": true
      },
      "FileData": {
        "type": "object",
        "description": "通过 URI 引用的文件数据。",
        "properties": {
          "fileUri": {
            "type": "string",
            "format": "uri",
            "description": "可被服务端访问的音频文件地址。"
          },
          "mimeType": {
            "type": "string",
            "description": "音频的 MIME 类型，例如 `audio/mp3`、`audio/wav`、`audio/m4a`、`audio/flac`、`audio/ogg`。"
          }
        },
        "required": [
          "fileUri",
          "mimeType"
        ]
      },
      "Blob": {
        "type": "object",
        "description": "内联二进制数据。",
        "properties": {
          "mimeType": {
            "type": "string",
            "description": "音频的 MIME 类型，需与音频实际格式一致。"
          },
          "data": {
            "type": "string",
            "contentEncoding": "base64",
            "description": "Base64 编码的音频字节。"
          }
        },
        "required": [
          "mimeType",
          "data"
        ]
      },
      "GenerationConfig": {
        "type": "object",
        "description": "生成配置。转写模型只需配置 `audioTranscriptionConfig`。",
        "properties": {
          "audioTranscriptionConfig": {
            "description": "音频转写配置，控制语言提示、转写模式、时间戳、说话人区分与自定义词汇。",
            "$ref": "#/components/schemas/AudioTranscriptionConfig"
          }
        },
        "required": [
          "audioTranscriptionConfig"
        ]
      },
      "AudioTranscriptionConfig": {
        "type": "object",
        "description": "音频转写配置。除 `languageCodes` 外，`customVocabulary`、`diarization`、`wordTimestamp`、`SMART` 模式均为实验性能力。",
        "properties": {
          "languageCodes": {
            "type": "array",
            "description": "可选。音频中可能出现的语言提示，取值为 BCP-47 语言代码，例如 `zh-CN`、`en-US`、`ja-JP`。已知语言时提供提示可提升准确率；省略时自动检测语言（支持 85 种以上语言，也支持同一段音频内混用多种语言）。",
            "items": {
              "type": "string"
            }
          },
          "customVocabulary": {
            "type": "array",
            "description": "可选。自定义词汇列表，用于引导模型正确识别领域术语、品牌名或专有名词。最多 1000 个词条，建议只保留约 100 个以内必要的词。不能与 `diarization` 或 `wordTimestamp` 同时使用，否则请求会被拒绝。",
            "items": {
              "type": "string"
            }
          },
          "diarization": {
            "type": "boolean",
            "description": "可选。是否启用说话人区分。启用后，响应中的 `audioTranscription.speakerLabel` 会标记说话人（例如 `spk_1`、`spk_2`），最多支持 8 位说话人；该能力目前为实验性。不能与 `customVocabulary` 同时使用。"
          },
          "wordTimestamp": {
            "type": "boolean",
            "description": "可选。是否返回字词级时间戳。启用后，`audioTranscription.words[]` 会包含每个识别出的字词及其 `startOffset`、`endOffset`；该能力目前为实验性，可能降低转写准确率。不能与 `customVocabulary` 同时使用。"
          },
          "mode": {
            "type": "string",
            "description": "可选。转写模式。`VERBATIM`（默认）逐字转写，保留填充词、重复、停顿和口误；`SMART` 智能转写，去除填充词与口吃、处理口头自我更正、自动分段与列表，并格式化日期、货币和数字。",
            "enum": [
              "MODE_UNSPECIFIED",
              "VERBATIM",
              "SMART"
            ],
            "x-enumDescriptions": [
              "未指定，等同 `VERBATIM`。",
              "逐字转写，保留填充词、重复、停顿和口误。",
              "智能转写，对转写结果做流畅度优化、结构化与格式化。"
            ],
            "default": "VERBATIM"
          }
        },
        "example": {
          "languageCodes": [
            "zh-CN"
          ],
          "mode": "SMART"
        }
      },
      "GenerateContentResponse": {
        "type": "object",
        "description": "转写响应。非流式返回完整结果；流式下每个 SSE 事件的 `data` 都是该结构的 JSON 分片。",
        "properties": {
          "candidates": {
            "type": "array",
            "description": "候选结果列表。",
            "items": {
              "$ref": "#/components/schemas/Candidate"
            }
          },
          "usageMetadata": {
            "description": "token 用量统计。",
            "$ref": "#/components/schemas/UsageMetadata"
          },
          "modelVersion": {
            "type": "string",
            "description": "仅输出。实际处理请求的模型版本。",
            "readOnly": true
          },
          "responseId": {
            "type": "string",
            "description": "仅输出。本次响应的唯一标识。",
            "readOnly": true
          }
        },
        "additionalProperties": true
      },
      "Candidate": {
        "type": "object",
        "description": "单个候选结果。",
        "properties": {
          "content": {
            "description": "模型返回的内容，转写文本与结构化结果位于 `parts[]`。",
            "$ref": "#/components/schemas/Content"
          },
          "finishReason": {
            "type": "string",
            "description": "仅输出。生成结束原因，正常结束为 `STOP`，达到最大输出长度时为 `MAX_TOKENS`。",
            "readOnly": true
          },
          "index": {
            "type": "integer",
            "format": "int32",
            "description": "仅输出。候选序号，从 0 开始。",
            "readOnly": true
          }
        },
        "additionalProperties": true
      },
      "Transcription": {
        "type": "object",
        "description": "结构化转写结果。当请求通过 `audioTranscriptionConfig` 启用转写时会出现在响应的 `part.audioTranscription` 中。",
        "properties": {
          "text": {
            "type": "string",
            "description": "仅输出。该片段的转写文本。",
            "readOnly": true
          },
          "languageCode": {
            "type": "string",
            "description": "仅输出。转写内容的 BCP-47 语言代码。",
            "readOnly": true
          },
          "speakerLabel": {
            "type": "string",
            "description": "仅输出。该片段说话人标签，例如 `spk_1`；仅在启用 `diarization` 时返回。",
            "readOnly": true
          },
          "words": {
            "type": "array",
            "description": "仅输出。字词级转写与时间信息；仅在启用 `wordTimestamp` 时返回。",
            "readOnly": true,
            "items": {
              "$ref": "#/components/schemas/WordInfo"
            }
          },
          "startOffset": {
            "type": "string",
            "format": "google-duration",
            "description": "仅输出。该片段相对于音频起始位置的开始偏移，例如 `1.5s`。",
            "readOnly": true
          },
          "endOffset": {
            "type": "string",
            "format": "google-duration",
            "description": "仅输出。该片段相对于音频起始位置的结束偏移，例如 `4.2s`。",
            "readOnly": true
          },
          "finished": {
            "type": "boolean",
            "description": "仅输出。该片段是否已结束；流式转写时可据此判断当前片段是否完成。",
            "readOnly": true
          }
        },
        "additionalProperties": true
      },
      "WordInfo": {
        "type": "object",
        "description": "单个识别字词的信息，仅在启用 `wordTimestamp` 时返回。",
        "properties": {
          "word": {
            "type": "string",
            "description": "仅输出。识别出的字词。",
            "readOnly": true
          },
          "startOffset": {
            "type": "string",
            "format": "google-duration",
            "description": "仅输出。该字词相对于音频起始位置的开始偏移。",
            "readOnly": true
          },
          "endOffset": {
            "type": "string",
            "format": "google-duration",
            "description": "仅输出。该字词相对于音频起始位置的结束偏移。",
            "readOnly": true
          }
        },
        "additionalProperties": true
      },
      "UsageMetadata": {
        "type": "object",
        "description": "token 用量。",
        "properties": {
          "promptTokenCount": {
            "type": "integer",
            "format": "int32",
            "description": "输入 token 数，音频按 token 计入。"
          },
          "candidatesTokenCount": {
            "type": "integer",
            "format": "int32",
            "description": "输出 token 数，即转写文本消耗的 token。"
          },
          "totalTokenCount": {
            "type": "integer",
            "format": "int32",
            "description": "总 token 数。"
          }
        },
        "additionalProperties": true
      }
    }
  }
}
```
