Implements the OpenAI Realtime API for voice conversation with audio streaming.
/**
* OpenAI Realtime Conversation Provider
*
* Full conversation mode: Twilio audio -> OpenAI Realtime (STT + LLM + TTS) -> mu-law -> Twilio.
*
* Uses the GA Realtime API (the beta API shape was retired by OpenAI with
* error code `beta_api_shape_disabled`). Event handlers accept both GA and
* legacy beta event names for safety.
*/
import WebSocket from "ws";
export interface RealtimeConversationConfig {
apiKey: string;
model?: string;
voice?: string;
systemPrompt?: string;
silenceDurationMs?: number;
vadThreshold?: number;
turnDetection?: "server_vad" | "semantic_vad";
vadEagerness?: "low" | "medium" | "high" | "auto";
language?: string;
tools?: RealtimeToolDefinition[];
}
/** Function tool exposed to the realtime model during a call. */
export interface Re
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key