$npx -y skills add chanjing-ai/chan-skills --skill chanjing-avatarUse Chanjing Avatar API for lip-syncing video generation (upload audio/video, create tasks, poll results).
| 1 | # Chanjing Avatar (Lip-Syncing) |
| 2 | |
| 3 | ## 功能说明 |
| 4 | |
| 5 | 调用蝉镜 **Avatar** Open API:上传音视频素材、创建对口型任务、轮询与获取结果链接。脚本为 Python HTTP/上传客户端,**不**依赖 ffmpeg/ffprobe。 |
| 6 | |
| 7 | ## 运行依赖 |
| 8 | |
| 9 | - **python3** 与同仓库 `scripts/*.py` |
| 10 | - **无** ffmpeg/ffprobe 门控 |
| 11 | |
| 12 | ## 环境变量与机器可读声明 |
| 13 | |
| 14 | - 环境变量键名与说明:**`manifest.yaml`**(`environment` 段)及本文 |
| 15 | - 变量、凭据、合规 **`permissions`**、**`clientPermissions`、`agentPolicy`**:**`manifest.yaml`** |
| 16 | |
| 17 | ## 使用命令 |
| 18 | |
| 19 | - **ClawHub**(slug 以注册表为准):`clawhub run chanjing-avatar` |
| 20 | - **本仓库**:`python skills/chanjing-avatar/scripts/create_task.py …`(流程见正文 **How to Use**) |
| 21 | |
| 22 | --- |
| 23 | |
| 24 | ## 登记与审稿(单一事实来源) |
| 25 | |
| 26 | 主凭据、上传/下载边界、浏览器引导等:**以 `manifest.yaml` 为准**。本篇 **How to Use** 起为 API 步骤说明。 |
| 27 | |
| 28 | ## When to Use This Skill |
| 29 | |
| 30 | Use this skill when the user needs to create lip-syncing videos (digital avatar videos) with synchronized mouth movements. |
| 31 | |
| 32 | Chanjing Avatar supports: |
| 33 | |
| 34 | * Text-driven or audio-driven lip-syncing |
| 35 | * Multiple system voices for TTS |
| 36 | * Video resolution customization |
| 37 | * Task status polling and callback |
| 38 | |
| 39 | ## How to Use This Skill |
| 40 | |
| 41 | **前置条件**:执行本 Skill 前,必须先通过 **chanjing-credentials-guard** 完成 AK/SK 与 Token 校验。凭据与审稿对表见 **`manifest.yaml`**。 |
| 42 | |
| 43 | ### Security & credentials(引用) |
| 44 | |
| 45 | 详见 **`manifest.yaml`** 中 **`credentials`** 与 **`clientPermissions`**(含本地上传、结果 URL、浏览器行为;合规见顶层 **`permissions`**)。 |
| 46 | |
| 47 | Multiple APIs need to be invoked. All share the domain: "https://open-api.chanjing.cc". |
| 48 | All requests communicate using json. |
| 49 | You should use utf-8 to encode and decode text throughout this task. |
| 50 | |
| 51 | 1. Obtain an `access_token`, which is required for all subsequent API calls |
| 52 | 2. Upload your video/audio files using the File Management API to get `file_id` |
| 53 | 3. Create a lip-syncing task with video and audio/text using these `file_id` values |
| 54 | 4. Poll the Query Task Detail API or use Task List API to check status |
| 55 | 5. Download the generated video using the url in response when status is completed |
| 56 | |
| 57 | ### Obtain AccessToken |
| 58 | |
| 59 | 从 `~/.chanjing/credentials.json` 读取 `app_id` 和 `secret_key`,若无有效 Token 则调用: |
| 60 | |
| 61 | ```http |
| 62 | POST /open/v1/access_token |
| 63 | Content-Type: application/json |
| 64 | ``` |
| 65 | |
| 66 | 请求体(使用本地配置的 app_id、secret_key): |
| 67 | |
| 68 | ```json |
| 69 | { |
| 70 | "app_id": "<从 credentials.json 读取>", |
| 71 | "secret_key": "<从 credentials.json 读取>" |
| 72 | } |
| 73 | ``` |
| 74 | |
| 75 | Response example: |
| 76 | |
| 77 | ```json |
| 78 | { |
| 79 | "trace_id": "8ff3fcd57b33566048ef28568c6cee96", |
| 80 | "code": 0, |
| 81 | "msg": "success", |
| 82 | "data": { |
| 83 | "access_token": "1208CuZcV1Vlzj8MxqbO0kd1Wcl4yxwoHl6pYIzvAGoP3DpwmCCa73zmgR5NCrNu", |
| 84 | "expire_in": 1721289220 |
| 85 | } |
| 86 | } |
| 87 | ``` |
| 88 | |
| 89 | Response field description: |
| 90 | |
| 91 | | First-level Field | Second-level Field | Description | |
| 92 | |---|---|---| |
| 93 | | code | | Response status code | |
| 94 | | msg | | Response message | |
| 95 | | data | | Response data | |
| 96 | | | access_token | Valid for one day, previous token will be invalidated | |
| 97 | | | expire_in | Token expiration time | |
| 98 | |
| 99 | Response Status Code Description |
| 100 | |
| 101 | | Code | Description | |
| 102 | |---|---| |
| 103 | | 0 | Success | |
| 104 | | 400 | Invalid parameter format | |
| 105 | | 40000 | Parameter error | |
| 106 | | 50000 | System internal error | |
| 107 | |
| 108 | ### Upload Media Files (File Management) |
| 109 | |
| 110 | Before creating a lip-syncing task, you **must** upload your video (and optional audio) files using the File Management API to obtain `file_id` values. |
| 111 | |
| 112 | The full documentation is here: `[File Management](https://doc.chanjing.cc/api/file/file-management.html)`. |
| 113 | |
| 114 | #### Step 1: Get upload URL |
| 115 | |
| 116 | ```http |
| 117 | GET /open/v1/common/create_upload_url |
| 118 | access_token: {{access_token}} |
| 119 | ``` |
| 120 | |
| 121 | Query params: |
| 122 | |
| 123 | | Key | Example | Description | |
| 124 | |---|---|---| |
| 125 | | service | lip_sync_video / lip_sync_audio | File usage purpose. Use `lip_sync_video` for driving video, `lip_sync_audio` for audio (if audio-driven). | |
| 126 | | name | 1.mp4 | Original file name including extension | |
| 127 | |
| 128 | You will get a response containing `sign_url`, `mime_type`, and `file_id`. Use the `sign_url` with HTTP `PUT` to upload the file, setting `Content-Type` to the returned `mime_type`. After the PUT completes, **poll the file detail API** until the file is ready (do not assume a fixed wait). Keep the returned `file_id` for `video_file_id` / `audio_file_id` below. |
| 129 | |
| 130 | **Polling:** Call `GET /open/v1/common/file_detail?id={{file_id}}` with `access_token` until the response `data.status` indicates success (e.g. `status === 2`). Only then use the `file_id` for the create task API. |
| 131 | |
| 132 | ### Create Lip-Syncing Task |
| 133 | |
| 134 | Submit a lip-syncing video creation task, which returns a video ID for polling later. |
| 135 | |
| 136 | ```http |
| 137 | POST /open/v1/video_lip_sync/create |
| 138 | access_token: {{access_token}} |
| 139 | Content-Type: application/json |
| 140 | ``` |
| 141 | |
| 142 | Request body example (TTS-driven): |
| 143 | |
| 144 | ```json |
| 145 | { |
| 146 | "video_file_id": "e284db4d95de4220afe78132158156b5", |
| 147 | "screen_width": 1080, |
| 148 | "screen_height": 1920, |
| 149 | "callback": "https: |