$npx -y skills add chanjing-ai/chan-skills --skill chanjing-ttsUse Chanjing TTS API to convert text to speech (list voices, create tasks, poll, download from returned URLs).
| 1 | # Chanjing TTS |
| 2 | |
| 3 | ## 功能说明 |
| 4 | |
| 5 | 调用蝉镜 **TTS** Open API:列举音色、创建合成任务、轮询并从接口返回 URL 下载音频。脚本**不**依赖 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-tts` |
| 20 | - **本仓库**:`python skills/chanjing-tts/scripts/create_task.py …`(见正文 **How to Use**) |
| 21 | |
| 22 | --- |
| 23 | |
| 24 | ## 登记与审稿(单一事实来源) |
| 25 | |
| 26 | 主凭据、下载行为、**`primaryEnv` 省略**等:**以 `manifest.yaml` 为准**。本篇 **How to Use** 起为 API 步骤说明。 |
| 27 | |
| 28 | ## When to Use This Skill |
| 29 | |
| 30 | Use this skill when the user needs to generate audio from text. |
| 31 | |
| 32 | Chanjing TTS supports: |
| 33 | |
| 34 | * both Chinese and English |
| 35 | * multiple system voices |
| 36 | * adjustment of speech speed |
| 37 | * sentence-level timestamp in result |
| 38 | |
| 39 | ## How to Use This Skill |
| 40 | |
| 41 | **前置条件(权限验证)**:执行本 Skill 前,必须先通过 **chanjing-credentials-guard** 完成 AK/SK 与 Token 校验。本 Skill 与 guard 使用同一套凭证(`~/.chanjing/credentials.json`);脚本在无凭证时会**执行 `open_login_page.py` 脚本**,在默认浏览器打开 AK/SK 注册/登录页,并提示配置命令。凭据与审稿对表见 **`manifest.yaml`**。 |
| 42 | |
| 43 | ### Security & credentials(引用) |
| 44 | |
| 45 | 详见 **`manifest.yaml`** 中 **`credentials`** 与 **`clientPermissions`**(及合规顶层 **`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. List all voice IDs and select one to use |
| 53 | 3. Call the Create Speech API, record `task_id` |
| 54 | 4. Poll the Query Speech Status API until success, then download generated audio file using the url in response |
| 55 | |
| 56 | ### Obtain AccessToken |
| 57 | |
| 58 | 从 `~/.chanjing/credentials.json` 读取 `app_id` 和 `secret_key`,若无有效 Token 则调用: |
| 59 | |
| 60 | ```http |
| 61 | POST /open/v1/access_token |
| 62 | Content-Type: application/json |
| 63 | ``` |
| 64 | |
| 65 | 请求体(使用本地配置的 app_id、secret_key): |
| 66 | |
| 67 | ```json |
| 68 | { |
| 69 | "app_id": "<从 credentials.json 读取>", |
| 70 | "secret_key": "<从 credentials.json 读取>" |
| 71 | } |
| 72 | ``` |
| 73 | |
| 74 | Response example: |
| 75 | |
| 76 | ```json |
| 77 | { |
| 78 | "trace_id": "8ff3fcd57b33566048ef28568c6cee96", |
| 79 | "code": 0, |
| 80 | "msg": "success", |
| 81 | "data": { |
| 82 | "access_token": "1208CuZcV1Vlzj8MxqbO0kd1Wcl4yxwoHl6pYIzvAGoP3DpwmCCa73zmgR5NCrNu", |
| 83 | "expire_in": 1721289220 |
| 84 | } |
| 85 | } |
| 86 | ``` |
| 87 | |
| 88 | Response field description: |
| 89 | |
| 90 | | First-level Field | Second-level Field | Description | |
| 91 | |---|---|---| |
| 92 | | code | | Response status code | |
| 93 | | msg | | Response message | |
| 94 | | data | | Response data | |
| 95 | | | access\_token | Valid for one day, previous token will be invalidated | |
| 96 | | | expire\_in | Token expiration time | |
| 97 | |
| 98 | Response Status Code Description |
| 99 | |
| 100 | | Code | Description | |
| 101 | |---|---| |
| 102 | | 0 | Success | |
| 103 | | 400 | Invalid parameter format | |
| 104 | | 40000 | Parameter error | |
| 105 | | 50000 | System internal error | |
| 106 | |
| 107 | ### Select a Voice ID |
| 108 | |
| 109 | Obtain all available voice IDs via API, and select one that fits the task at hand. |
| 110 | The dialect/accent can be deduced from the voice name. |
| 111 | |
| 112 | ```http |
| 113 | GET /open/v1/list_common_audio |
| 114 | access_token: {{access_token}} |
| 115 | ``` |
| 116 | |
| 117 | Use the following request body: |
| 118 | |
| 119 | ```json |
| 120 | { |
| 121 | "page": 1, |
| 122 | "size": 100 |
| 123 | } |
| 124 | |
| 125 | Response example: |
| 126 | |
| 127 | ```json |
| 128 | { |
| 129 | "trace_id": "25eb6794ffdaaf3672c25ed9efbe49c6", |
| 130 | "code": 0, |
| 131 | "msg": "success", |
| 132 | "data": { |
| 133 | "list": [ |
| 134 | { |
| 135 | "id": "f9248f3b1b42447fb9282829321cfcf2", |
| 136 | "grade": 0, |
| 137 | "name": "带货小芸", |
| 138 | "gender": "female", |
| 139 | "lang": "multilingual", |
| 140 | "desc": "", |
| 141 | "speed": 1, |
| 142 | "pitch": 1, |
| 143 | "audition": "https://res.chanjing.cc/chanjing/res/upload/ms/2025-06-05/7945e0474b8cb526e884ee7e28e4af8d.wav" |
| 144 | }, |
| 145 | { |
| 146 | "id": "f5e69c1bbe414bec860da3294e177625", |
| 147 | "grade": 0, |
| 148 | "name": "方言口音老奶奶", |
| 149 | "gender": "female", |
| 150 | "lang": "multilingual", |
| 151 | "desc": "", |
| 152 | "speed": 1, |
| 153 | "pitch": 1, |
| 154 | "audition": "https://res.chanjing.cc/chanjing/res/upload/ms/2025-04-30/1b248ad05953028db5a6bcba9a951164.wav" |
| 155 | }, |
| 156 | ... |
| 157 | ], |
| 158 | "page_info": { |
| 159 | "page": 1, |
| 160 | "size": 100, |
| 161 | "total_count": 98, |
| 162 | "total_page": 1 |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | ``` |
| 167 | |
| 168 | Response field description: |
| 169 | |
| 170 | | First-level Field | Second-level Field | Third-level Field | Description | |
| 171 | |---|---|---|---| |
| 172 | | code | | | Response status code | |
| 173 | | message | | | Response message | |
| 174 | | data | | | Response data | |
| 175 | | | list | List data | Public voice - list data | |
| 176 | | | | id | Voice ID | |
| 177 | | | | name | Voice name, if it includes a place name, the generated speech is in dialect | |
| 178 | | | | gender | Gender | |
| 179 | | | | lang | Language | |
| 180 | | | | desc | Description | |
| 181 | | | | speed | Speech speed | |
| 182 | | | | pitch |