Skip to main content

Integrate a speech synthesis model

Call Token Plan speech synthesis models in Agent tools to convert text to audio and download it locally.

Supported models

ModelCapability
qwen-audio-3.0-tts-plusSpeech 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 installed locally.
  • Your AI coding tool supports Slash Commands. For configuration paths of other tools, see Other tools.

Endpoint

POST https://token-plan.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer Use Authorization: Bearer $ANTHROPIC_AUTH_TOKEN in the request header. The response returns 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 (text to synthesize), 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 to synthesize speech and download the audio:

```bash
RESPONSE=$(curl -s -X POST "https://token-plan.cn-beijing.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 downloaded audio file path.

Step 2: Synthesize speech

In Claude Code, enter /text-to-speech Hello, welcome to Model Studio. To change the voice, specify it in the instruction, for example /text-to-speech Say hello with longanlingxin.

Request parameters

ParameterRequiredDescription
modelYesSpeech synthesis model ID.
input.textYesText to synthesize.
input.voiceYesVoice, for example longanhuan_v3.6.
input.formatNoAudio format. Supports mp3, pcm, wav, and opus. Default: mp3.
input.sample_rateNoSample rate. Default: 22050.
For more parameters, see Qwen-Audio-TTS speech synthesis HTTP API. For voices, see Qwen-Audio-TTS voice list.

Response

  • Audio URL: output.audio.url.
  • URL expiration: output.audio.expires_at.
  • Billed characters: usage.characters.
  • Audio URLs expire. Download them promptly.

Limits

  • Voices must match the model version. For available voices, see the voice list.
  • Billing is based on valid characters. Actual consumption is shown in the console usage statistics.

Other tools

For extension mechanisms and configuration paths of other tools, see Integration overview. Save the Slash Command content above to the corresponding path.