APTalkmoji OpenAI Realtime API Avatar
Docs›SDK Introduction

OpenAI Realtime API Avatar

Swap the Gemini Live backend for OpenAI's Realtime API. Both use a bidirectional WebSocket — the audio and lip-sync pipeline are identical; only the WebSocket endpoint and auth change.

ℹ️

OpenAI Realtime support is a configuration overlay. The core lip-sync controller (Natural Lip Sync) works the same regardless of which service sends the audio.

How to swap Gemini for OpenAI Realtime

Step 1 — Add your OpenAI API key

# .env
OPENAI_API_KEY=sk-proj-...
# Also set a public key for client-side WebSocket authentication:
PUBLIC_OPENAI_API_KEY=sk-proj-...
⚠️

Like Gemini Live, the OpenAI Realtime WebSocket is opened directly from the browser. Use a separate, usage-restricted key for PUBLIC_OPENAI_API_KEY.

Step 2 — Configure the project to use OpenAI

In your project settings, set the Voice engine to openai-realtime and pick a voice:

PATCH /api/projects/:id
{
  "voiceEngine": "openai-realtime",
  "voice": "alloy"    # alloy | echo | shimmer | fable | onyx | nova
}

OpenAI Realtime WebSocket pipeline

The OpenAI Realtime API uses a similar bidirectional WebSocket pattern to Gemini Live:

Browser mic (24kHz PCM16)
    │
    ▼
WebSocket ──────────────────────► wss://api.openai.com/v1/realtime
                                         │  model: gpt-4o-realtime-preview
    ◄──────────────────────────── PCM16 audio chunks (24kHz)
    │                              + text transcription deltas
    │
    ├─ Web Audio API → speaker
    └─ FFT analyser → lip-sync → Rive

Key differences from Gemini Live

AspectGemini LiveOpenAI Realtime
Model gemini-3.8-live gpt-4o-realtime-preview
Input sample rate 16 kHz 24 kHz
Output sample rate 24 kHz 24 kHz
Session init BidiGenerateContentSetup message session.update event
Audio format PCM16 base64 PCM16 base64 (input_audio_format: "pcm16")
Interruption Supported Supported (response.cancel)
Context window 1M tokens 128k tokens

RAG with OpenAI Realtime

The RAG pipeline is engine-agnostic. Before the session starts, the widget calls POST /embed/:publicId/retrieve with the session opening message as the query. The retrieved chunks are injected into the instructions field of the session.update event:

// Session setup message (sent after WebSocket opens)
{
  "type": "session.update",
  "session": {
    "model": "gpt-4o-realtime-preview",
    "voice": "alloy",
    "instructions": `${systemPrompt}\n\nKnowledge base:\n${retrievedChunks}`,
    "input_audio_format": "pcm16",
    "output_audio_format": "pcm16",
    "turn_detection": {
      "type": "server_vad",
      "threshold": 0.5,
      "silence_duration_ms": 800
    }
  }
}

Voices

Voice IDCharacter
alloyNeutral, clear — good general-purpose voice
echoWarm male voice
shimmerClear female voice, slightly higher pitch
fableExpressive British accent
onyxDeep, authoritative male
novaWarm, friendly female
💡

The lip-sync quality is the same for all three voice engines (Gemini Live, ElevenLabs, OpenAI Realtime) because it's driven by amplitude analysis of the audio, not by the voice engine itself. See Natural Lip Sync for details.