在 Agent 工具中呼叫 Token Plan 語音合成模型,將文字轉為音訊並下載到本機。
支援的模型
| 模型 | 能力 |
|---|---|
qwen-audio-3.0-tts-plus | 語音合成 |
前提
- 已訂閱 Token Plan,並取得以
sk-sp-開頭的 API Key。取得方式請參閱整合概覽。 - 本機已安裝 Python 3.9 以上版本。
- 使用的 AI 程式設計工具支援 Slash Command。其他工具的設定路徑請參閱其他工具。
端點
POST https://token-plan.ap-southeast-1.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer
請求標頭使用 Authorization: Bearer $ANTHROPIC_AUTH_TOKEN。回應傳回音訊 URL。
步驟一:建立 Slash Command
將套餐 API Key 設定為環境變數 $ANTHROPIC_AUTH_TOKEN。
在專案根目錄建立 .claude/commands/text-to-speech.md,並寫入以下內容:
步驟二:合成語音
在 Claude Code 中輸入 /text-to-speech 你好,欢迎使用百炼。如需更換音色,請在指令中寫明音色,例如 /text-to-speech 用 longanlingxin 说:你好。
請求參數
| 參數 | 必選 | 說明 |
|---|---|---|
model | 是 | 語音合成模型 ID。 |
input.text | 是 | 待合成文字。 |
input.voice | 是 | 音色,例如 longanhuan_v3.6。 |
input.format | 否 | 音訊格式,支援 mp3、pcm、wav、opus,預設 mp3。 |
input.sample_rate | 否 | 取樣率,預設 22050。 |
返回結果
- 音訊 URL:
output.audio.url。 - URL 過期時間:
output.audio.expires_at。 - 計費字元數:
usage.characters。 - 音訊 URL 具有時效,產生後請及時下載。
限制
- 音色需與模型版本匹配,可用音色以音色清單為準。
- 計費依有效字元數計算,實際以主控台用量統計為準。