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

# Kling 对口型生成

> 驱动源视频中人物的嘴型，匹配文本（TTS）或已有音频文件中的语音。

对口型生成可以让视频中的人物"说"出您指定的话，支持两种输入方式——文本驱动（内置 TTS 合成语音）或直接使用音频文件驱动。

**该接口需要 `session_id`**，必须先调用[人脸识别](/zh/guides/model-api/kuaishou/kling-identify-face)接口获取。

## 工作流概览

```
1. identify-face  →  session_id
2. advanced-lip-sync（session_id + 语音输入）  →  task_id
3. 轮询 GET /kling/v1/videos/advanced-lip-sync/{task_id}  →  视频 URL
```

## 输入方式

### 文本驱动——内置 TTS

提供 `text`、`voice_id` 和 `voice_language`，平台使用指定音色将文字合成为语音，再驱动嘴型。

<CodeGroup>
  ```bash cURL theme={null}
  curl https://www.anyfast.ai/kling/v1/videos/advanced-lip-sync \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "input": {
        "session_id": "YOUR_SESSION_ID",
        "text": "你好，欢迎来到我的频道",
        "voice_id": "girlfriend_1_cn",
        "voice_language": "zh"
      }
    }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://www.anyfast.ai/kling/v1/videos/advanced-lip-sync",
      headers={
          "Authorization": "Bearer YOUR_API_KEY",
          "Content-Type": "application/json"
      },
      json={
          "input": {
              "session_id": "YOUR_SESSION_ID",
              "text": "你好，欢迎来到我的频道",
              "voice_id": "girlfriend_1_cn",
              "voice_language": "zh"
          }
      }
  )
  task = response.json()
  print(f"Task ID: {task['task_id']}")
  ```
</CodeGroup>

### 音频驱动——使用已有音频文件

提供 `audio_url`，直接用音频文件驱动嘴型。

<CodeGroup>
  ```bash cURL theme={null}
  curl https://www.anyfast.ai/kling/v1/videos/advanced-lip-sync \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "input": {
        "session_id": "YOUR_SESSION_ID",
        "audio_url": "https://example.com/speech.mp3"
      }
    }'
  ```

  ```python Python theme={null}
  import requests
  import time

  # 步骤 1：创建任务
  response = requests.post(
      "https://www.anyfast.ai/kling/v1/videos/advanced-lip-sync",
      headers={
          "Authorization": "Bearer YOUR_API_KEY",
          "Content-Type": "application/json"
      },
      json={
          "input": {
              "session_id": "YOUR_SESSION_ID",
              "audio_url": "https://example.com/speech.mp3"
          }
      }
  )
  task_id = response.json()["task_id"]

  # 步骤 2：轮询结果
  while True:
      result = requests.get(
          f"https://www.anyfast.ai/kling/v1/videos/advanced-lip-sync/{task_id}",
          headers={"Authorization": "Bearer YOUR_API_KEY"}
      ).json()
      status = result["data"]["status"]
      print(f"状态: {status}")
      if status == "succeeded":
          print("视频 URL:", result["data"]["data"]["task_result"]["videos"][0]["url"])
          break
      elif status == "failed":
          print("失败原因:", result["data"].get("fail_reason"))
          break
      time.sleep(5)
  ```
</CodeGroup>

## 请求参数

| 参数                     | 类型     | 必填     | 说明                                                                                                                      |
| ---------------------- | ------ | ------ | ----------------------------------------------------------------------------------------------------------------------- |
| `input.session_id`     | string | ✅      | 人脸识别步骤返回的会话 ID                                                                                                          |
| `input.face_image_url` | string | 否      | 人脸参考图片 URL，用于提升人物一致性                                                                                                    |
| `input.text`           | string | 文本模式必填 | 人物要说的文字内容                                                                                                               |
| `input.voice_id`       | string | 文本模式必填 | TTS 音色 ID。可查阅[音色 ID 参考文档](https://docs.qingque.cn/s/home/eZQDvafJ4vXQkP8T9ZPvmye8S?identityId=2E1MlYrrPk4)在线试听并选择合适的音色。 |
| `input.voice_language` | string | 文本模式必填 | 语言代码：`zh`（中文）或 `en`（英文）                                                                                                 |
| `input.audio_url`      | string | 音频模式必填 | 音频文件的公网 URL                                                                                                             |

## 轮询结果

任务创建后，使用 `GET /kling/v1/videos/advanced-lip-sync/{task_id}` 查询状态，参考[任务查询](/zh/guides/model-api/kuaishou/kling-task-query)文档。状态流转：`queued` → `processing` → `succeeded` / `failed`。

成功后，视频下载链接在 `data.data.task_result.videos[0].url`。

<Card title="前置步骤：人脸识别" icon="user" href="/zh/guides/model-api/kuaishou/kling-identify-face">
  必须先调用此接口获取 session\_id。
</Card>

<Card title="音色 ID 参考文档" icon="volume" href="https://docs.qingque.cn/s/home/eZQDvafJ4vXQkP8T9ZPvmye8S?identityId=2E1MlYrrPk4">
  在线试听所有可用音色，选择适合的 voice\_id 参数值。
</Card>

<Card title="API 参考" icon="code" href="/zh/api-reference/model-api/kuaishou/kling-lip-sync">
  查看 Kling 对口型生成的交互式 API 文档。
</Card>

<script src="/feedback.js" />
