> ## Documentation Index
> Fetch the complete documentation index at: https://docs.token.poryf.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 千问语音合成

> 千问语音合成 Qwen-Audio-TTS：把文字转成语音，OpenAI 兼容的 /v1/audio/speech 接口，按字符计费。

阿里通义千问语音合成模型，把文字转成自然的语音，支持多种音色、语速，以及用一句话指令控制语气和情绪。接口与 OpenAI 的语音接口兼容，直接返回音频文件。

* 模型 ID：`qwen-audio-3.1-tts-plus`
* 接口：`POST https://token.poryf.com/v1/audio/speech`（同步返回音频文件）
* [价格](https://token.poryf.com/pricing/qwen-audio-3.1-tts-plus)

## 请求参数

请求头带上 `Authorization: Bearer YOUR_API_KEY` 和 `Content-Type: application/json`。

**model** `string` *required*

`qwen-audio-3.1-tts-plus`

**input** `string` *required*

要合成的文字。单次最多 20,000 个计费字符（一个汉字按 2 个字符计）。

**voice** `string`

音色 ID，如 `longanhuan_v3.1`。不传，或传 OpenAI 的音色名（如 `alloy`）时，使用默认音色 `longanhuan_v3.1`。

**response\_format** `string` (default: mp3)

音频格式：`mp3`、`wav`、`pcm`、`opus`。

**speed** `number` (default: 1)

语速，0.5–2。

**instructions** `string`

用自然语言描述语气、情绪或方言，如「用开心的语气」。

**volume** `number` (default: 50)

音量，0–100。

**pitch** `number` (default: 1)

音调，0.5–2。

**sample\_rate** `integer`

采样率：8000、12000、16000、22050、24000、44100、48000。

**language** `string`

文本语言提示，如 `zh`、`en`、`ja`。

## 示例

```bash theme={null}
curl https://token.poryf.com/v1/audio/speech \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-audio-3.1-tts-plus",
    "input": "欢迎使用千问语音合成，今天天气不错。",
    "voice": "longanhuan_v3.1",
    "response_format": "mp3"
  }' \
  --output speech.mp3
```

用 OpenAI Python SDK：

```python theme={null}
from openai import OpenAI

client = OpenAI(api_key="YOUR_API_KEY", base_url="https://token.poryf.com/v1")
response = client.audio.speech.create(
    model="qwen-audio-3.1-tts-plus",
    voice="longanhuan_v3.1",
    input="欢迎使用千问语音合成。",
)
response.write_to_file("speech.mp3")
```

## 计费

* 按字符计费，单价按每万字符标示。一个汉字（以及日文假名、韩文）按 2 个字符计，英文字母、数字、标点和空格按 1 个字符计。例如「你好，世界。Hello!」计 16 个字符。
* 按实际合成的字符数结算，合成失败不扣费。实时单价见 [模型广场](https://token.poryf.com/pricing/qwen-audio-3.1-tts-plus)。

> [!WARNING]
>
> * 暂不支持流式输出（`stream_format: "sse"`），接口在整段音频合成完成后一次返回。
> * 音色 ID 填错会返回 400，请使用通义千问语音合成的音色 ID。

通用错误码见 [错误码](https://docs.token.poryf.com/errors.md)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.