API文档
ClonyVoice提供本地REST API,让您将文字转语音、语音克隆和音频处理集成到您的应用程序中。ClonyVoice打开时,API在您的设备上运行。
基础URL
API在本地以下地址可用:
http://127.0.0.1:8765
认证
所有API请求需要通过X-API-Key HTTP头传递API密钥。在ClonyVoice桌面应用的API选项卡中创建密钥。
X-API-Key: cvk_your_api_key_here
端点
Voices
| Method | Path | Description | Scope |
|---|---|---|---|
| GET | /api/voices | List all voices | voices:read |
| GET | /api/voices/{id} | Get voice details | voices:read |
| PUT | /api/voices/{id} | Update voice | voices:write |
| DELETE | /api/voices/{id} | Delete voice | voices:write |
| GET | /api/favorites | Get favorites | voices:read |
| POST | /api/favorites/{id} | Toggle favorite | voices:write |
Text-to-Speech (TTS)
| Method | Path | Description | Scope |
|---|---|---|---|
| POST | /api/generate/clone | Generate speech (clone) | tts:generate |
| POST | /api/generate/preset | Generate speech (preset) | tts:generate |
| POST | /api/generate/design | Generate speech (design) | tts:generate |
| POST | /api/text/split | Split text into sentences | audio:process |
| POST | /api/generation/cancel | Cancel generation | tts:generate |
Voice Cloning & Design
| Method | Path | Description | Scope |
|---|---|---|---|
| POST | /api/clone/create | Create voice clone | clone:create |
| POST | /api/clone/create-multi | Multi-sample clone | clone:create |
| POST | /api/design/create | Create voice from description | clone:create |
Audio Processing
| Method | Path | Description | Scope |
|---|---|---|---|
| POST | /api/transcribe | Transcribe audio (Whisper) | audio:process |
| POST | /api/audio-duration | Get audio duration | audio:process |
System
| Method | Path | Description | Scope |
|---|---|---|---|
| GET | /api/system/stats | CPU, RAM, GPU stats | system:read |
| GET | /api/system/info | Hardware info | system:read |
| GET | /api/api-keys | List API keys | system:read |
| POST | /api/api-keys | Create API key | system:read |
WebSocket
| Method | Path | Description | Scope |
|---|---|---|---|
| WS | /ws | Real-time progress updates | ws:connect |
代码示例
curl -X POST "http://127.0.0.1:8765/api/generate/clone" \
-H "X-API-Key: cvk_your_key" \
-H "Content-Type: application/json" \
-d '{
"voice_id": "voice_abc123",
"text": "Hello, world!",
"language": "en"
}'
import requests
response = requests.post(
"http://127.0.0.1:8765/api/generate/clone",
headers={"X-API-Key": "cvk_your_key"},
json={
"voice_id": "voice_abc123",
"text": "Hello, world!",
"language": "en"
}
)
print(response.json())
const response = await fetch(
"http://127.0.0.1:8765/api/generate/clone",
{
method: "POST",
headers: {
"X-API-Key": "cvk_your_key",
"Content-Type": "application/json"
},
body: JSON.stringify({
voice_id: "voice_abc123",
text: "Hello, world!",
language: "en"
})
}
);
const data = await response.json();
console.log(data);
速率限制
每个API密钥具有按作用域的速率限制(每分钟请求数)。超出时,API返回HTTP 429。默认限制可按密钥配置。
作用域
每个端点需要特定的作用域。密钥默认被授予所有作用域。
| Scope | Description | Default limit/min |
|---|---|---|
tts:generate | Generate speech (TTS) | 10 |
tts:timeline | Timeline editor access | 30 |
voices:read | Read voices & categories | 60 |
voices:write | Modify / delete voices | 20 |
clone:create | Create voice clones | 2 |
audio:process | Process audio files | 5 |
projects:read | Read compositions | 60 |
projects:write | Modify compositions | 20 |
system:read | Read system info | 60 |
ws:connect | WebSocket connection | 5 |