> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vmeg.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 翻译文本片段（同步）

> 一次请求翻译纯文本片段，译文立即在 HTTP `data` 中返回。**不**处理视频或音频 — 媒体请使用 **创建翻译配音任务**。



## OpenAPI

````yaml /zh/api-reference/openapi.json post /openapi/v1/task/translate/create
openapi: 3.1.0
info:
  title: VMEG Open API
  description: >-
    将 VMEG 集成到产品中：翻译并配音视频或音频、语音合成、声音克隆、纯文本翻译，以及管理 API 侧文件。响应格式为 `{ code,
    message, data }`；`code === 200` 表示成功。
  version: 1.0.0
servers:
  - url: https://api.vmeg.ai
    description: 生产环境
security:
  - apiKeyAuth: []
tags:
  - name: 媒体翻译
    x-group: 视频与音频翻译配音
    description: >-
      对上传的视频或音频做端到端本地化：识别语音、翻译文稿、生成 AI 配音（克隆或预设音色），并返回配音后的媒体。可选字幕与口型同步。**仅异步** —
      配音文件通过 [Webhook](/zh/guides/webhooks) 投递。这不是纯文本翻译；见
      [媒体翻译](/zh/guides/products/media-translation)。
  - name: TTS
    x-group: 文本转语音（TTS）
    description: >-
      用预设或克隆音色将文本合成为自然语音。**同步**在 HTTP 响应中返回音频 URL；**异步**通过
      [Webhook](/zh/guides/webhooks) 投递结果。见
      [文本转语音](/zh/guides/products/text-to-speech)。
  - name: 声音克隆
    x-group: 声音克隆
    description: >-
      从短参考录音创建可复用音色，返回可用于 TTS 或翻译配音任务的 `voiceId`。见
      [声音克隆](/zh/guides/products/voice-clone)。
  - name: 文本翻译
    x-group: 文本翻译（仅文本）
    description: >-
      翻译纯文本片段，不处理音频或视频。媒体中的口语内容请使用 **视频与音频翻译配音**。见
      [文本翻译](/zh/guides/products/text-translation)。
  - name: 任务管理
    x-group: 任务状态与历史
    description: >-
      列出、查看或删除通过各产品 API 创建的任务。无法依赖 Webhook 时可轮询 `GET .../tasks/detail`。范围限定于当前
      **API Key**。见 [产品概览](/zh/guides/products/overview)。
  - name: 资产 - 素材
    x-group: 上传文件（素材）
    description: >-
      上传并管理用于翻译配音任务的视频/音频。流程：走完完整上传（预签名或分片 → 登记）→ 将已注册的 `materialId` 传入
      create-async。见 [素材上传](/zh/guides/assets/material-upload)。
  - name: 资产 - 音色
    x-group: 音色（预设与克隆）
    description: 列出 TTS 预设音色，或管理已克隆音色。克隆音色通过 **声音克隆** 创建。见 [音色](/zh/guides/assets/voices)。
paths:
  /openapi/v1/task/translate/create:
    post:
      tags:
        - 文本翻译
      summary: 翻译文本片段（同步）
      description: 一次请求翻译纯文本片段，译文立即在 HTTP `data` 中返回。**不**处理视频或音频 — 媒体请使用 **创建翻译配音任务**。
      operationId: translateCreateSync
      parameters:
        - $ref: '#/components/parameters/IdempotencyKeyRequired'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OpenApiTranslateCreateRequest'
      responses:
        '200':
          description: 成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenApiTranslateCreateResponse'
components:
  parameters:
    IdempotencyKeyRequired:
      name: X-Idempotency-Key
      in: header
      required: true
      description: 创建任务或修改持久化数据的 `POST` 必填（最长 64 字符）。见 [幂等](/zh/guides/idempotency)。
      schema:
        type: string
        maxLength: 64
  schemas:
    OpenApiTranslateCreateRequest:
      type: object
      required:
        - language
        - segments
      properties:
        language:
          type: object
          required:
            - source
            - target
          properties:
            source:
              type: string
              example: zh-CN
              description: 源语言 locale（BCP-47）。见 [支持的语言](/zh/guides/supported-languages)。
            target:
              type: string
              example: en-US
              description: 目标语言 locale（BCP-47）。见 [支持的语言](/zh/guides/supported-languages)。
          description: 翻译源语言与目标语言
        segments:
          type: array
          maxItems: 50
          items:
            $ref: '#/components/schemas/OpenApiTranslateSegment'
          description: 待翻译文本片段（最多 50 条）
        options:
          $ref: '#/components/schemas/OpenApiTranslateOptions'
          description: 可选翻译设置（上下文、场景、术语表、prompt）
    OpenApiTranslateCreateResponse:
      allOf:
        - $ref: '#/components/schemas/OpenApiResponseBase'
        - type: object
          properties:
            data:
              description: 同步 HTTP 响应中返回的译文片段。
              allOf:
                - $ref: '#/components/schemas/OpenApiTranslateCreateData'
    OpenApiTranslateSegment:
      type: object
      required:
        - text
      properties:
        text:
          type: string
          description: 该片段的原文
        gender:
          $ref: '#/components/schemas/OpenApiTranslateSpeakerGender'
          description: 该片段说话人性别。枚举：`male` 或 `female`。
        speaker:
          type: string
          example: Speaker A
          description: 多说话人场景下的说话人标识，便于保持人称与音色一致
        locale:
          type: string
          example: zh-CN
          description: 当与 `language.source` 不同时的单句语言
        context:
          type: array
          items:
            type: string
          description: 单句邻句上下文，优先于 `options.sourceContext`；在 `provided_only` 且片段时间不连续时尤其有用
        start:
          type: number
          description: 该句在原文时间轴上的起始秒数；与 `end` 成对使用以标定时间区间
        end:
          type: number
          description: 该句在原文时间轴上的结束秒数；须与 `start` 同时提供且不小于 `start`
    OpenApiTranslateOptions:
      type: object
      description: 可选翻译设置
      properties:
        sourceContext:
          $ref: '#/components/schemas/OpenApiTranslateSourceContext'
          description: 如何使用相邻原文语境；省略时默认为 `independent`
        sceneCustomized:
          $ref: '#/components/schemas/OpenApiTranslateSceneCustomized'
          description: 场景与表达风格提示
        glossary:
          type: object
          additionalProperties:
            type: string
          description: 术语表（源词 → 首选译文）
        prompt:
          type: string
          description: 追加到翻译指令的自定义 prompt
        skipMissingTranslationCheck:
          type: boolean
          default: false
          description: 为 `true` 时跳过「每句均有译文」的校验
    OpenApiResponseBase:
      type: object
      properties:
        code:
          type: integer
          example: 200
          description: 业务码；200 表示成功
        message:
          type: string
          example: ''
          description: 当 `code` 非成功时的说明信息
      required:
        - code
    OpenApiTranslateCreateData:
      type: object
      properties:
        taskId:
          type: string
          description: Open API 任务 ID
        items:
          type: array
          items:
            $ref: '#/components/schemas/OpenApiTranslateResultItem'
          description: 译文片段，与请求 segments 按索引对齐
        createdAt:
          type: string
          description: 任务创建时间（ISO 8601）
    OpenApiTranslateSpeakerGender:
      type: string
      description: 翻译片段说话人性别
      enum:
        - male
        - female
      example: male
    OpenApiTranslateSourceContext:
      type: object
      description: 全局邻句上下文策略；优先级低于各句的 `context`
      properties:
        mode:
          type: string
          enum:
            - independent
            - provided_only
            - neighbor
          default: independent
          description: >-
            `independent` — 逐句独立翻译。`provided_only` — 使用各句 `context`
            中提供的邻句。`neighbor` — 从按序排列的 segments 中按 `contextWindow` 自动取邻句
        contextWindow:
          type: integer
          minimum: 1
          maximum: 20
          default: 5
          description: 仅当 `mode` 为 `neighbor` 时生效：向前后各扩展的邻段条数（1–20）
    OpenApiTranslateSceneCustomized:
      type: object
      description: 按场景定制的翻译行为
      properties:
        scene:
          type: string
          enum:
            - video
            - audio
            - subtitle
            - voiceover
          default: video
          description: 供翻译模型判断的内容类型
        allowStutter:
          type: boolean
          default: true
          description: 译文中是否可保留原文中的口吃/重复等不流畅表达
    OpenApiTranslateResultItem:
      type: object
      properties:
        text:
          type: string
          description: 译文
        errorMessage:
          type: string
          description: 该片段翻译失败时的原因
  securitySchemes:
    apiKeyAuth:
      type: http
      scheme: bearer
      description: >-
        在 **`Authorization`** 请求头中传入 API Key（`Bearer <api_key>`）。见
        [鉴权](/zh/guides/authentication)。

````