OpenAI Realtime API指南2026:构建可实时打断和倾听的语音Agent

2026-08-02 约 6 分钟阅读

想要一个一秒内响应的语音助手,而不是STT转LLM再转TTS的串行延迟。

OpenAI Realtime API: Speech-to-Speech Without the Pipeline Lag

The OpenAI Realtime API, launched in October 2024, lets you send audio directly to the model and receive audio back - no separate speech-to-text or text-to-speech calls in between. Latency drops to roughly the time it takes the model to think, and the API supports natural turn-taking, including the model hearing you while it speaks and stopping when interrupted.

Why Teams Choose It Over the Classic Pipeline

The classic stack (Whisper to transcribe, an LLM to think, TTS to speak) has two problems: each hop adds 300-800ms, and the pipeline has no sense of conversation timing. The Realtime API keeps one WebSocket connection open and streams audio both ways. For phone agents, kiosks, and in-car assistants, that changes the feel from walkie-talkie to conversation.

What You Get in the API

Pricing Reality Check

Audio is billed per minute, and audio tokens are more expensive than text tokens - roughly $0.06 per minute of audio input and $0.24 per minute of audio output on the standard realtime model tier (see OpenAI's pricing page for current rates). A 5-minute support call therefore costs on the order of a dollar and a half before any text-tool calls. That is why many production voice agents only use the Realtime API for the actual conversation and fall back to cheaper text calls for background lookups.

A Minimal Working Example

from openai import OpenAI

client = OpenAI()
with client.beta.realtime.connect(model="gpt-4o-realtime") as conn:
    conn.send({"type": "session.update", "session": {"instructions": "You are a hotel concierge."}})
    # stream mic audio in, receive audio deltas out

The pattern is the same for every app: open a socket, send session config, stream audio in, play audio deltas out.

FAQ

Do I need a separate TTS model? No - the model produces speech directly.

Can I use it for phone calls? Yes, it pairs with telephony providers like Twilio; the audio bridges into the same WebSocket.

Is the Realtime API more expensive than text? Yes, audio tokens cost more than text tokens per minute of use.

Does it support languages other than English? Yes, the underlying models handle dozens of languages natively.

相关文章
2026-06-29
高收益主线龙头策略——不花钱的数据,也能抓到龙头
2026-06-29
你笔记本里,藏着一个AI
2026-07-14
免费AI编程助手 2026 配置指南:VS Code 5分钟装 Continue、Copilot、Windsurf

💬 评论 (0)

暂无评论,来说两句吧~

登录后评论