Call a Token Plan speech synthesis model from an Agent tool, convert text to audio, and download the audio locally.
Supported models
| Model | Capability |
|---|---|
qwen-audio-3.0-tts-plus | Speech synthesis |
For more models, see models supported by Token Plan.
Prerequisites
- A Token Plan subscription and an API key that starts with
sk-sp-. For details, see Integration overview. - Python 3.9 or later.
- Your AI coding tool supports Slash Commands. For configuration paths of other tools, see Other tools.
Interface
POST https://token-plan.ap-southeast-1.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer
Use Authorization: Bearer $ANTHROPIC_AUTH_TOKEN in the request header. The response contains an audio URL.
Step 1: Create a Slash Command
Configure the Token Plan API key as the environment variable $ANTHROPIC_AUTH_TOKEN.
Create .claude/commands/text-to-speech.md in the project root and add the following content:
Call the Token Plan speech synthesis API to convert text to an audio file and download it locally.
Text to synthesize: $ARGUMENTS
## Steps
1. Extract text, voice (default: longanhuan_v3.6), format (default: mp3), and sample_rate (default: 22050). If a model is specified, use that model; otherwise use qwen-audio-3.0-tts-plus.
2. Use the Bash tool to run the following command:
```bash
RESPONSE=$(curl -s -X POST "https://token-plan.ap-southeast-1.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer" \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-audio-3.0-tts-plus",
"input": {
"text": "<text>",
"voice": "<voice>",
"format": "<format>",
"sample_rate": <sample_rate>
}
}')
AUDIO_URL=$(printf '%s' "$RESPONSE" | python3 -c 'import json,sys; print(json.load(sys.stdin)["output"]["audio"]["url"])')
curl -s -o "speech_$(date +%Y%m%d_%H%M%S).<format>" "$AUDIO_URL"
```
3. Output the path of the downloaded audio file.
Step 2: Synthesize speech
In Claude Code, enter /text-to-speech Hello, welcome to Model Studio. To change the voice, specify it in the command, for example /text-to-speech use longanyang to say: Hello.
Request parameters
| Parameter | Required | Description |
|---|---|---|
model | Yes | Speech synthesis model ID. |
input.text | Yes | Text to synthesize. |
input.voice | Yes | Voice, for example longanhuan_v3.6. |
input.format | No | Audio format. Supports mp3, pcm, wav, and opus. Default: mp3. |
input.sample_rate | No | Sample rate. Default: 22050. |
For more parameters, see CosyVoice speech synthesis HTTP API. For available voices, see CosyVoice voice list.
Response
- Audio URL:
output.audio.url. - URL expiration time:
output.audio.expires_at. - Billed characters:
usage.characters. - Audio URLs expire. Download the audio promptly.
Limits
- The voice must match the model version. For available voices, see the voice list.
- Billing is based on valid characters. Actual Credits consumption is shown in Usage in the console.
Other tools
For extension mechanisms and configuration paths of other tools, see Integration overview. Save the Slash Command above to the corresponding path.