Integrate the speech recognition model
Submit a local audio file or audio URL to the Token Plan speech recognition model from an Agent tool and return the transcription.
Supported models
| Model | Capability | Type |
|---|---|---|
qwen-audio-3.0-asr-flash | Speech recognition | Non-real-time |
For more models, see models supported by Token Plan.
Prerequisites
- A Token Plan subscription. For the Personal Edition, get the
sk-sp-API key from My Subscription (Personal). For the Team Edition, assign a seat in Member Management, then get the API key. - Python 3.9 or later.
- A publicly accessible audio URL or a local audio file. The audio must be no longer than 5 minutes. Formats such as
wav,mp3, andopusare supported. For details, see Audio specifications.
Interface
POST https://token-plan.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
Use Authorization: Bearer $ANTHROPIC_AUTH_TOKEN in the request header. For the request body and response fields, see the sections below.
Step 1: Create a Slash Command
Configure the Token Plan API key (prefixed with sk-sp-) as the environment variable $ANTHROPIC_AUTH_TOKEN for script authentication.
Create .claude/commands/speech-to-text.md in the project root and add the following content:
Call the Token Plan speech recognition API to transcribe audio into text.
Audio file or URL: $ARGUMENTS
## Steps
1. Confirm that the input is a local audio path or a publicly accessible URL. The audio must be no longer than 5 minutes. For format and size limits, see the audio specifications in the Model Studio speech recognition documentation.
2. Install dependencies: pip install requests
3. Use the Bash tool to run the following Python script. The script reads TOKEN_PLAN_API_KEY first, then ANTHROPIC_AUTH_TOKEN. Do not display the key or write it to files or logs.
```python
import base64
import json
import os
import sys
from pathlib import Path
import requests
MIME_TYPES = {
"aac": "audio/aac",
"amr": "audio/amr",
"flac": "audio/flac",
"m4a": "audio/mp4",
"mp3": "audio/mpeg",
"ogg": "audio/ogg",
"opus": "audio/opus",
"wav": "audio/wav",
"webm": "audio/webm",
}
source = sys.argv[1]
key = os.environ.get("TOKEN_PLAN_API_KEY") or os.environ.get("ANTHROPIC_AUTH_TOKEN")
if not key:
raise SystemExit("Token Plan API Key not found.")
if source.startswith(("http://", "https://")):
audio_data = source
audio_format = Path(source.split("?")[0]).suffix.lstrip(".").lower() or "mp3"
else:
path = Path(source)
audio_format = path.suffix.lstrip(".").lower()
mime_type = MIME_TYPES.get(audio_format, f"audio/{audio_format}")
audio_data = f"data:{mime_type};base64,{base64.b64encode(path.read_bytes()).decode()}"
payload = {
"model": "qwen-audio-3.0-asr-flash",
"input": {
"messages": [
{
"role": "user",
"content": [
{"type": "input_audio", "input_audio": {"data": audio_data}}
],
}
]
},
"parameters": {"format": audio_format},
}
response = requests.post(
"https://token-plan.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation",
headers={"Authorization": f"Bearer {key}", "Content-Type": "application/json"},
json=payload,
timeout=300,
)
if not response.ok:
raise SystemExit(f"{response.status_code}: {response.text}")
result = response.json()
print(result.get("text") or json.dumps(result, ensure_ascii=False, indent=2))
```
4. Output the transcription. If detailed results are needed, show the `sentence` and `words` fields in the response JSON.
Step 2: Transcribe audio
In Claude Code, enter /speech-to-text ./meeting.wav, or pass an audio URL: /speech-to-text https://example.com/audio.mp3.
Request parameters
| Parameter | Description |
|---|---|
model | Set to qwen-audio-3.0-asr-flash. |
input.messages[0].content[0].input_audio.data | An audio URL, or a Base64 Data URI in the format data:audio/{format};base64,{data}. |
parameters.format | Required. The audio format, such as wav or mp3. |
parameters.sample_rate | Optional. The audio sample rate, such as 16000. |
parameters.language_hints | Optional. Language codes for recognition, up to 4, such as ["zh"]. |
For all parameters and response fields, see Non-real-time speech recognition HTTP API.
Other tools
For extension mechanisms and configuration file paths for other tools, see "Tool configuration paths" in Integration overview.
Limits
- Token Plan provides the non-real-time speech recognition model
qwen-audio-3.0-asr-flash. - A single audio input must be no longer than 5 minutes. For file size and format limits, see Audio specifications.
- Speech recognition uses the DashScope protocol. The endpoint is
https://token-plan.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation.