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 |
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.maas.qwencloudapi.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:
Step 2: Synthesize speech
In Claude Code, enter /text-to-speech Hello, welcome to QwenCloud. 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. |
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.