Qwen-Audio-3.1-Realtime
NEWOverview
Qwen-Audio-3.1-Realtime is a next-generation real-time, full-duplex speech model with enhanced spoken-language reasoning, multi-turn instruction following, empathetic communication, and role-playing capabilities, balancing intelligent responses with a natural conversational rhythm. Improved noise rejection, understanding of multi-party conversations, and real-time contextual understanding allow the model to handle interruptions, wait for users to finish speaking, and take turns more naturally in real-world settings. The model supports multilingual conversations and intelligent tool use, connecting to knowledge bases and business systems while naturally integrating task results into the conversation. With stronger safeguards for refusing unsafe requests and enforcing safety boundaries, it delivers more intelligent, natural, and reliable interactions across customer service, workplace collaboration, and voice-based companionship.
Input
Output
Features
Prefix Completion
Enable Partial Mode when calling the Qwen API to make the model continue strictly from your provided prefix text.View docsFunction Calling
Use function calling to connect large language models with external tools and systems.View docsCache
Context Cache stores shared prefixes for long-context requests to reduce repeated computation, improve latency, and lower cost.View docsStructured Outputs
Structured Outputs help ensure the model returns a JSON string in the expected format.View docsPricing
- Input: Audio$6.4Per 1M tokens
- Input: Text$0.8Per 1M tokens
- Output: Text$6.4Per 1M tokens
- Output: Text&Audio (Output text is not charged)$24Per 1M tokens
Rate Limits & Context
- Max Input245K
- Max Output16K
- Max Input (Thinking)245K
- Max Output (Thinking)16K
- Context262K
- Max Reasoning2K
- TPMTokens Per Minute100K
- RPMRequests Per Minute60
API Reference
Call APIimport asyncio
import base64
import json
import os
import pyaudio
import websockets
API_KEY = os.environ["DASHSCOPE_API_KEY"]
URL = "wss://maas.qwencloudapi.com/api-ws/v1/realtime?model=qwen-audio-3.1-realtime-plus"
pya = pyaudio.PyAudio()
mic = pya.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True)
spk = pya.open(format=pyaudio.paInt16, channels=1, rate=24000, output=True)
async def main():
headers = {"Authorization": f"Bearer {API_KEY}"}
async with websockets.connect(URL, additional_headers=headers) as ws:
await ws.send(json.dumps({
"type": "session.update",
"session": {
"modalities": ["text", "audio"],
"voice": "longanqian",
"turn_detection": {
"type": "server_vad",
"threshold": 0.5,
"silence_duration_ms": 500
}
}
}))
async def send_audio():
while True:
data = await asyncio.to_thread(mic.read, 3200, False)
await ws.send(json.dumps({
"type": "input_audio_buffer.append",
"audio": base64.b64encode(data).decode()
}))
await asyncio.sleep(0.02)
async def recv_events():
async for msg in ws:
event = json.loads(msg)
t = event["type"]
if t == "response.audio.delta":
audio = base64.b64decode(event["delta"])
await asyncio.to_thread(spk.write, audio)
elif t == "conversation.item.input_audio_transcription.completed":
print(f"[You] {event['transcript']}")
elif t == "response.audio_transcript.done":
print(f"[AI] {event['transcript']}")
elif t == "error":
print(f"[Error] {event['error']['message']}")
await asyncio.gather(send_audio(), recv_events())
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
mic.close()
spk.close()
pya.terminate()
print("\nSession ended.")