qwen-audio-3.1-tts-next
This is a unified audio generation model that supports character speech, multi-person dialogue, sound effects and environmental sounds. You can provide only text, or you can provide reference audio, so that different lines can use the reference timbre.
When calling ShangHai Do, use POST /v1/audio/speech and this site token. input can write text directly; when reference audio or more generation parameters are needed, it can be changed to an object containing multiple fields.
Basic information
| Item | Content |
|---|---|
| Site model name | qwen-audio-3.1-tts-next |
| Model type | Unified audio generation (voice, sound effects, environmental sounds) |
| Request interface | POST /v1/audio/speech |
request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model |
The text | is | . Fixedly fill in qwen-audio-3.1-tts-next. |
input |
Text or object | Yes | Fill in the sound description directly, or use the object field in the table below. Text descriptions are also limited to 3000 characters. |
response_format |
Text | No | wav, mp3, pcm, default wav; corresponding to format in the object. |
speed |
Number | No | 0.5 ~ 2, default 1; corresponding to rate in the object. |
stream_format |
Text | No | Omit or fill in audio. The interface still returns the complete audio and does not return it while generating. |
Complete parameters of object input
The following fields are placed in input. It is recommended to write the object without repeatedly filling in the outermost response_format or speed; if both are filled in, the values must be the same, otherwise a parameter error will be returned. When optional fields are omitted, the default settings listed in the following table are used.
| Field | Type | Required | Meaning, value and default behavior |
|---|---|---|---|
text_prompt |
Text | is | Voice description, character, tone and lines, 1 to 3000 characters. Use @voice1, @voice2, @voice3 to quote the corresponding reference audio. |
references |
Array | No | Reference audio list, up to 3 items; each item can be up to 30 seconds, no more than 10 MB, supports WAV, MP3, OGG Opus. When omitted, only text is generated. |
references[].audio_url |
Text | Choose one of two for each | Public network where audio can be downloaded directly http or https address. Login cannot be required, and the address cannot contain username or password. |
references[].audio_data |
Text | Choose one from each | Encode the audio file into text and submit it together with the format prefix, such as data:audio/wav;base64,... ;You cannot just fill in the Base64 content without prefix. |
format |
Text | No | Output format: wav, mp3, pcm, default wav; Opus output is not supported. |
sample_rate |
Integer | No | Sampling rate, that is, the number of times the sound is recorded per second, in Hertz. Supports 8000, 16000, 24000, 44100, 48000, the default is 48000. |
channels |
Integer | No | 1 is mono, 2 It is two-channel, the default is 2. |
volume |
Integer | No | Volume, 0 ~ 100, default 50. |
rate |
Number | No | Speech speed, 0.5 ~ 2, default 1, the bigger, the faster. |
seed |
Integer | No | The random seed generated this time, the default is 42. Used to control generation changes and cannot replace reference audio fixed character timbres. |
enable_cbr |
true / false | No | Only MP3 is valid. true means that the amount of compressed data per second for the entire segment is fixed, false means that it adjusts with the complexity of the sound, and the default is false. |
bit_rate |
Integer | No | Valid only when MP3 and enable_cbr: true, default 128 . The unit is kilobits per second. The actual output is limited by the sampling rate and encoding gear, see the table below. This parameter cannot be filled in for other output formats. |
quality |
Integer | No | Valid only when MP3 and enable_cbr: false, 0 ~ 9, default 5; 0 has the highest quality, the larger the number, the lower the quality. |
enable_aigc_tag |
true / false | No | Whether to add artificial intelligence to generate content identification, the default is false. |
Next does not accept the voice tone number, nor does it accept the outermost instructions. The character, tone and lines should be written in text_prompt; do not use the text or instruction fields of Flash.
How to fill in the reference audio
references The first one corresponds to @voice1, the second one corresponds to @voice2, and the third one corresponds to @voice3. Only fill in one of audio_url and audio_data for each audio piece. Do not cite this number in the text without submitting a corresponding reference.
Local WAV files use the data:audio/wav;base64, prefix, MP3 uses data:audio/mpeg;base64,, and OGG Opus uses data:audio/ogg;base64,, followed by the Base64 encoding of the file. This site also accepts the prefixes corresponding to audio/x-wav, audio/mp3, and audio/opus. The reference file does not support bare PCM; the input supports OGG Opus, which does not mean the output supports Opus.
When using a public address, please ensure that the audio can be downloaded directly and meets the above format, size and length requirements. Local files can be submitted directly by following the Python example below.
MP3 fixed bit rate output range
| Sampling rate (Hz) | Output bit rate range (kilobits per second) |
|---|---|
8000 |
8~64 |
16000、24000 |
8~160 |
44100、48000 |
32~320 |
This is the encoded output range. It does not mean that every integer in the range has a corresponding gear, nor is it a range limit set by this site for input integers. Specified values outside the range will be restricted to the corresponding range by the model service. When using a fixed code rate, fill in enable_cbr: true and bit_rate; when using a variable code rate, fill in enable_cbr: false and quality.
Request Example
First press Voice Interface General Instructions to set the site address SHANHAI_BASE_URL and the site token SHANHAI_API_KEY.
Generate sound with text only
curl --fail-with-body "$SHANHAI_BASE_URL/v1/audio/speech" \
-H "Authorization: Bearer $SHANHAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-audio-3.1-tts-next",
"input": "雨后森林中,几只小鸟清脆地鸣叫,伴随轻柔的风吹树叶声。",
"response_format": "wav"
}' \
-o qwen-audio-next.wav
Using reference audio
When the same character speaks different lines, reuse the same reference audio and only modify text_prompt. The request structure is shown below. The Chinese placeholder content in audio_data must be replaced with the real file encoding:
{
"model": "qwen-audio-3.1-tts-next",
"input": {
"text_prompt": "@voice1 用沉稳、威严的司令声音说:“向前推进!”",
"references": [
{ "audio_data": "data:audio/wav;base64,替换成参考音频的Base64内容" }
],
"format": "wav",
"sample_rate": 48000,
"channels": 2,
"rate": 1.15,
"seed": 42
}
}
Local files can be submitted directly using the Python example below. Prepare a copy of reference.wav that takes no more than 30 seconds and is 10 MB, and put it in the same directory as the script; only Python 3 is required, and there is no need to install additional dependencies. Set the aforementioned environment variables before running, and the generated result will be saved as qwen-audio-next-reference.wav.
import base64
import json
import os
from pathlib import Path
from urllib import error, request
base_url = os.environ["SHANHAI_BASE_URL"].rstrip("/")
api_key = os.environ["SHANHAI_API_KEY"]
reference = Path("reference.wav").read_bytes()
if not reference or len(reference) > 10_000_000:
raise SystemExit("参考音频不能为空,且不能超过 10 MB。")
audio_data = "data:audio/wav;base64," + base64.b64encode(reference).decode("ascii")
payload = {
"model": "qwen-audio-3.1-tts-next",
"input": {
"text_prompt": "@voice1 用平静、清晰的语气说:“欢迎使用ShangHai Do。”",
"references": [{"audio_data": audio_data}],
"format": "wav",
"sample_rate": 48000,
"channels": 2,
"rate": 1,
"seed": 42,
},
}
req = request.Request(
base_url + "/v1/audio/speech",
data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
headers={
"Authorization": "Bearer " + api_key,
"Content-Type": "application/json",
},
method="POST",
)
try:
with request.urlopen(req, timeout=180) as response:
audio = response.read()
except error.HTTPError as exc:
detail = exc.read().decode("utf-8", errors="replace")
raise SystemExit(f"生成失败(状态码 {exc.code}):{detail}")
except error.URLError as exc:
raise SystemExit(f"连接失败:{exc.reason}")
if not audio:
raise SystemExit("接口未返回音频。")
Path("qwen-audio-next-reference.wav").write_bytes(audio)
print("已保存 qwen-audio-next-reference.wav")
When generating the next line, keep the same reference.wav and references, and only change the text. For multi-person conversations, the reference audios of different people are added in order, and are cited in the text as @voice1 and @voice2 respectively. Don't just rely on fixing the seed to maintain your tone.
Specify MP3 compression method
The following is the request body using a fixed bitrate of 128 kilobits per second. Change enable_cbr to false, remove bit_rate and fill in quality to change to variable code rate:
{
"model": "qwen-audio-3.1-tts-next",
"input": {
"text_prompt": "一位女性自然地说:“你好,欢迎使用ShangHai Do。”",
"format": "mp3",
"sample_rate": 48000,
"enable_cbr": true,
"bit_rate": 128
}
}
Return results
The successful response body is an audio binary file, not JSON, and there is no need to download the audio address separately. Save in requested format; when using pcm, the player also needs to know the sample rate and number of channels. This site currently returns complete files and does not provide return while generating or word-level timestamps.
encountered a problem
If you encounter problems with calling or configuration, please contact the site customer service and provide the model name, error time and error information to facilitate troubleshooting.