మాట్లాడే సమాధానానికి పలు శోధనలు అవసరమైతే బ్రౌజర్ వాయిస్ సంభాషణ క్లిష్టమవుతుంది. మోడల్ పూర్తయిన ఒక స్పందనలో అనేక ఫంక్షన్ కాల్స్ తిరిగి ఇవ్వవచ్చు. ప్రతి ఫలితాన్ని అసలు call_id తో పంపాలి; అన్ని ఫలితాలు పంపిన తర్వాతే కొత్త స్పందన ప్రారంభించాలి. ఈ గైడ్ డెవలపర్లకు పూర్తి localhost ఉదాహరణ ఇస్తుంది: ప్రత్యక్ష మైక్రోఫోన్ ఇన్‌పుట్, WebRTC స్ట్రీమింగ్ ప్లేబ్యాక్, రెండు కల్పిత చదవడానికి మాత్రమే సాధనాలు, పునరావృత సంభాషణలు, మధ్యలో ఆపినప్పుడు శుభ్రపరచడం. ఇది మా ప్రాథమిక బ్రౌజర్ వాయిస్ గైడ్ ను విస్తరిస్తుంది; అది బయటి సాధనాలు లేకుండానే మాట్లాడే సమాధానం ఇస్తుంది.

పెద్ద మార్పు

  • ఏం మారింది: OpenAI అందించే Realtime API ప్రత్యక్ష వాయిస్ సెషన్‌లో ఫంక్షన్ కాల్స్ ఇవ్వవచ్చు. ఉదాహరణ call_id ద్వారా పూర్తయిన కాల్స్‌ను స్థానిక ఫలితాలకు జతచేసి, తర్వాత మోడల్‌ను కొనసాగించమంటుంది.
  • ఇది ఎందుకు ముఖ్యం: పలు చదవడానికి మాత్రమే శోధనలపై ఆధారపడే వాయిస్ సమాధానాన్ని డెవలపర్ పరీక్షించవచ్చు. మైక్రోఫోన్ సేకరణ, ప్లేబ్యాక్ బ్రౌజర్‌లో, సాధారణ API కీ స్థానిక సర్వర్‌లో ఉంటాయి.
  • గమనించాల్సినవి: స్థానిక తనిఖీలు కృత్రిమ సంఘటనలతో క్రమం, శుభ్రపరచడం పరీక్షిస్తాయి. మీ ఖాతా, బ్రౌజర్, పరికరాలు, నెట్‌వర్క్ వినిపించే సరైన సమాధానాలు, ఊహించిన బిల్లు ఇస్తాయో మీ స్వంత చెల్లింపు సెషన్‌లో నిర్ధారించాలి.

ఉదాహరణ OpenAI సాధారణ Realtime WebRTC ఎండ్‌పాయింట్ /v1/realtime/calls తో gpt-realtime-2.1 ను వాడుతుంది. వేరైన GPT-Live సెషన్ ప్రోటోకాల్ వాడదు. కింద రెండు “గ్రంథాలయ” విలువలు కల్పిత సాఫ్ట్‌వేర్ పరీక్ష డేటా, నిజమైన స్థల సమాచారం కాదు. BIG CHANGE 2026 అక్టోబర్ 20న ప్రస్తుత WebRTC, సంభాషణ, సాధన, సంఘటన పత్రాలను తనిఖీ చేసింది. స్థానిక కృత్రిమ కంట్రోలర్, బ్రౌజర్ తనిఖీలు నడిపాం; చెల్లింపు API సెషన్ ప్రారంభించలేదు, నిజమైన మైక్రోఫోన్ లేదా ధ్వని పరీక్షించలేదు.

1. ప్రాప్యత తనిఖీ చేసి ఐదు ఫైళ్లు సృష్టించండి

Node.js 22.6 లేదా కొత్తది, మైక్రోఫోన్, స్పీకర్లున్న ప్రస్తుత బ్రౌజర్, అలాగే gpt-realtime-2.1 కు ప్రాప్యత గల OpenAI API ప్రాజెక్ట్ కావాలి. దాని మోడల్ పేజీ Free స్థాయికి మద్దతు లేదంటుంది. ముందుగా API బిల్లింగ్, ప్రాజెక్ట్ అభ్యర్థన రేటు, ఖర్చు పరిమితులు చూడండి; ChatGPT సభ్యత్వం API వినియోగాన్ని చెల్లించదు. మీ సాధారణ స్థానిక రహస్య నిర్వహణ ద్వారా OPENAI_API_KEY ను సర్వర్ ప్రాసెస్ వాతావరణంలో ఉంచండి. ఈ ఫైళ్లు, బ్రౌజర్ కోడ్, లిఖిత సంభాషణల్లో కీ రాయవద్దు. OpenAI కి పంపేందుకు అనుమతించిన మాటలనే వాడండి.

కొత్త డైరెక్టరీ సృష్టించి, కింద ఐదు పూర్తి బ్లాకులను వాటి పై ఇచ్చిన ఫైల్ పేర్లతో సేవ్ చేయండి. .mjs ఎక్స్‌టెన్షన్లను అలాగే ఉంచి, అన్ని ఫైళ్లు ఒకే డైరెక్టరీలో పెట్టండి. సర్వర్ 127.0.0.1:3000 వద్ద వింటుంది. స్థానిక పేజీ SDP offer ను తీసుకుని సర్వర్ కీతో OpenAI కి పంపి SDP answer తిరిగి ఇస్తుంది. బ్రౌజర్‌కు సాధారణ API కీ అందదు. స్థానిక Host, Origin తనిఖీలు ప్రదర్శనను localhost కు పరిమితం చేయడంలో సహాయపడతాయి; భాగస్వామ్య సేవ వినియోగదారులను ప్రామాణీకరించవు.

server.mjs

JavaScript
import express from "express";

const app = express();
// This demo accepts only the local page, including protection against DNS rebinding.
app.use((req, res, next) => {
  const hosts = ["localhost:3000", "127.0.0.1:3000"];
  if (!hosts.includes(req.get("host"))) return res.status(403).send("Local host required");
  if (req.method === "POST" && req.get("origin") !== `http://${req.get("host")}`) {
    return res.status(403).send("Same-origin local page required");
  }
  next();
});
app.use(express.text({ type: "application/sdp", limit: "64kb" }));

app.get("/", (_req, res) => res.sendFile("index.html", { root: process.cwd() }));
app.get("/controller.mjs", (_req, res) => res.sendFile("controller.mjs", { root: process.cwd() }));

app.post("/session", async (req, res) => {
  if (!process.env.OPENAI_API_KEY) return res.status(500).send("Server API key missing");
  if (typeof req.body !== "string" || !req.body.startsWith("v=")) {
    return res.status(400).send("Expected an SDP offer");
  }

  const form = new FormData();
  form.set("sdp", req.body);
  form.set("session", JSON.stringify({
    type: "realtime",
    model: "gpt-realtime-2.1",
    output_modalities: ["audio"],
    audio: { output: { voice: "marin" } },
    instructions: "Answer questions about the fictional demo library only using its read-only tools. State clearly that the data is synthetic software test data, not real venue information. For a lookup that may take noticeable time, give one short spoken progress preamble when useful, then call the tools. A preamble is never a result. Do not invent missing information. If a tool result is an error, say that lookup failed. Respond concisely in speech.",
    tools: [
      { type: "function", name: "get_demo_hours", description: "Read synthetic demo-library opening hours; no external account or network.", parameters: { type: "object", properties: {}, additionalProperties: false } },
      { type: "function", name: "get_demo_address", description: "Read synthetic demo-library address; no external account or network.", parameters: { type: "object", properties: {}, additionalProperties: false } }
    ],
    tool_choice: "auto"
  }));

  try {
    const upstream = await fetch("https://api.openai.com/v1/realtime/calls", {
      method: "POST",
      headers: { Authorization: `Bearer ${process.env.OPENAI_API_KEY}` },
      body: form,
      signal: AbortSignal.timeout(25000)
    });
    const answer = await upstream.text();
    if (!upstream.ok) {
      console.error("Realtime session rejected", upstream.status);
      return res.status(502).send(`OpenAI session request failed (${upstream.status})`);
    }
    res.type("application/sdp").send(answer);
  } catch (error) {
    console.error("Realtime session network failure", error.name);
    res.status(502).send("Could not reach the Realtime API");
  }
});

app.listen(3000, "127.0.0.1", () => console.log("Open http://localhost:3000"));

index.html

HTML
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Local Realtime voice and read-only tool check</title>
<h1>Local voice and tool check</h1>
<p>The library data in this demo is synthetic software test data.</p>
<button id="start">Start voice</button>
<button id="stop" disabled>Stop and release microphone</button>
<p id="status" role="status">Idle</p>
<audio id="reply" autoplay controls></audio>
<pre id="events" aria-label="Event status"></pre>
<script type="module">
import { ToolController } from "/controller.mjs";

const start = document.querySelector("#start");
const stop = document.querySelector("#stop");
const status = document.querySelector("#status");
const events = document.querySelector("#events");
const reply = document.querySelector("#reply");
let current;

function note(line) {
  events.textContent = `${line}\n${events.textContent}`.slice(0, 3000);
}

// These values are synthetic test fixtures, never real business records.
async function runDemoTool(call, signal) {
  if (signal.aborted) throw Error("interrupted");
  let args;
  try { args = JSON.parse(call.arguments); } catch { return { ok: false, error: "Invalid arguments" }; }
  if (!args || Array.isArray(args) || typeof args !== "object" || Object.keys(args).length) {
    return { ok: false, error: "Expected an empty object" };
  }
  if (call.name === "get_demo_hours") return { ok: true, value: "Synthetic demo library hours: Monday-Friday 09:00-17:00." };
  if (call.name === "get_demo_address") return { ok: true, value: "Synthetic demo library address: 1 Example Lane. This is not a real venue." };
  return { ok: false, error: "Tool is not allowed" };
}

function closeSession(session = current, message = "Stopped") {
  if (!session || session.closed) return;
  session.closed = true;
  clearTimeout(session.setupTimer);
  clearTimeout(session.sessionTimer);
  session.controller?.close();
  session.abort.abort();
  session.mic?.getTracks().forEach(track => track.stop());
  if (session.pc) session.pc.onconnectionstatechange = null;
  session.dc?.close();
  session.pc?.close();
  reply.pause();
  if (current === session) {
    current = null;
    reply.srcObject = null;
    start.disabled = false;
    stop.disabled = true;
    status.textContent = message;
    note(message);
  }
}

start.onclick = async () => {
  const session = { abort: new AbortController(), closed: false };
  current = session;
  start.disabled = true;
  stop.disabled = false;
  status.textContent = "Requesting microphone";
  events.textContent = "";
  session.setupTimer = setTimeout(() => closeSession(session, "Setup timed out; microphone stopped"), 30000);
  try {
    const mic = await navigator.mediaDevices.getUserMedia({ audio: true });
    if (session.closed) { mic.getTracks().forEach(track => track.stop()); return; }
    session.mic = mic;
    const pc = session.pc = new RTCPeerConnection();
    pc.ontrack = event => {
      if (session.closed) return;
      reply.srcObject = event.streams[0];
      reply.play().catch(() => note("Playback blocked; press Play on the audio control"));
    };
    pc.onconnectionstatechange = () => {
      if (session.closed) return;
      note(`Peer: ${pc.connectionState}`);
      if (pc.connectionState === "connected") {
        clearTimeout(session.setupTimer);
        clearTimeout(session.sessionTimer);
        session.sessionTimer = setTimeout(() => closeSession(session, "Local session limit reached; microphone stopped"), 55 * 60000);
        status.textContent = "Connected; ask about the synthetic demo library";
      }
      if (["failed", "closed", "disconnected"].includes(pc.connectionState)) closeSession(session, "Connection ended; microphone stopped");
    };
    pc.addTrack(mic.getAudioTracks()[0], mic);
    const dc = session.dc = pc.createDataChannel("oai-events");
    const send = event => {
      if (session.closed || dc.readyState !== "open") throw Error("Event channel is not open");
      dc.send(JSON.stringify(event));
    };
    session.controller = new ToolController({
      send, runTool: runDemoTool,
      status: note,
      fatal: message => closeSession(session, `${message}; microphone stopped`)
    });
    dc.onmessage = message => {
      if (session.closed) return;
      let event;
      try { event = JSON.parse(message.data); } catch { closeSession(session, "Invalid event; microphone stopped"); return; }
      if (event.type === "session.created") note("Realtime session created");
      if (event.type === "output_audio_buffer.cleared") note("Server cleared unplayed speech after interruption");
      session.controller.handle(event).catch(() => closeSession(session, "Controller failed; microphone stopped"));
    };
    dc.onclose = () => { if (!session.closed) closeSession(session, "Event channel closed; microphone stopped"); };
    dc.onerror = () => closeSession(session, "Event channel failed; microphone stopped");
    const offer = await pc.createOffer();
    await pc.setLocalDescription(offer);
    if (session.closed) return;
    const response = await fetch("/session", {
      method: "POST", headers: { "Content-Type": "application/sdp" },
      body: offer.sdp, signal: session.abort.signal
    });
    if (!response.ok) throw Error(`Session request failed (${response.status})`);
    const answer = await response.text();
    if (session.closed) return;
    await pc.setRemoteDescription({ type: "answer", sdp: answer });
    if (!session.closed) status.textContent = "Signaling complete; waiting for connection";
  } catch (error) {
    if (!session.closed) closeSession(session, `Start failed: ${error.message}`);
  }
};
stop.onclick = () => closeSession();
window.addEventListener("pagehide", () => closeSession());
</script>
</html>

controller.mjs

JavaScript
// The same controller runs in the browser and in the synthetic local checks.
export class ToolController {
  constructor({ send, runTool, status, fatal, setTimer = setTimeout, clearTimer = clearTimeout }) {
    Object.assign(this, { send, runTool, status, fatal, setTimer, clearTimer });
    this.epoch = 0;
    this.rounds = 0;
    this.counter = 0;
    this.responses = new Map();
    this.pending = null;
    this.closed = false;
  }

  abortPending() {
    if (!this.pending) return;
    this.pending.abort.abort();
    if (this.pending.timer) this.clearTimer(this.pending.timer);
    this.pending = null;
  }

  close() {
    this.closed = true;
    this.epoch++;
    this.abortPending();
    this.responses.clear();
  }

  fail(message) {
    if (this.closed) return;
    this.status(message);
    this.close();
    this.fatal(message);
  }

  interrupt() {
    if (this.closed) return;
    this.epoch++;
    this.rounds = 0;
    this.abortPending();
    this.status("Speech detected; interrupted result discarded");
  }

  async handle(event) {
    if (this.closed) return;
    if (event.type === "error") {
      this.fail(`Realtime error: ${event.error?.code || event.error?.message || "unknown"}`);
      return;
    }
    if (event.type === "input_audio_buffer.speech_started") { this.interrupt(); return; }
    if (event.type === "response.created") {
      if (event.response?.id) this.responses.set(event.response.id, this.epoch);
      return;
    }
    if (event.type === "conversation.item.done") {
      const p = this.pending;
      const id = event.item?.id;
      if (!p || p.epoch !== this.epoch || !p.acks.has(id)) return;
      p.acks.delete(id);
      if (p.acks.size === 0) {
        if (p.timer) this.clearTimer(p.timer);
        this.pending = null;
        if (!p.abort.signal.aborted && !this.closed && p.epoch === this.epoch) {
          this.status("All tool outputs acknowledged; resuming response");
          this.send({ type: "response.create" });
        }
      }
      return;
    }
    if (event.type !== "response.done") return;
    const response = event.response;
    const id = response?.id;
    const responseEpoch = this.responses.get(id);
    this.responses.delete(id);
    if (responseEpoch === undefined || responseEpoch !== this.epoch) return;
    this.status(`Response ${id}: ${response.status || "unknown"}`);
    if (response.status !== "completed") return; // Never execute partial/cancelled calls.
    const calls = (response.output || []).filter(item => item.type === "function_call");
    if (!calls.length) return;
    if (this.pending) { this.fail("Overlapping tool batches in one turn"); return; }
    if (calls.length > 8 || ++this.rounds > 3) { this.fail("Tool call or round bound reached"); return; }
    const ids = new Set();
    for (const call of calls) {
      if (call.status !== "completed" || !call.call_id || ids.has(call.call_id)) {
        this.fail("Incomplete or repeated function call ID"); return;
      }
      ids.add(call.call_id);
    }
    const p = { epoch: this.epoch, abort: new AbortController(), acks: new Set(), timer: null };
    this.pending = p;
    this.status(`Executing ${calls.length} read-only local call(s) from ${id}`);
    const outputs = await Promise.all(calls.map(async call => {
      try { return { call, result: await this.runTool(call, p.abort.signal) }; }
      catch { return { call, result: { ok: false, error: "Local lookup failed" } }; }
    }));
    if (this.closed || this.pending !== p || p.epoch !== this.epoch || p.abort.signal.aborted) return;
    try {
      for (const { call, result } of outputs) {
        const itemId = `tool_output_${++this.counter}`;
        p.acks.add(itemId);
        this.send({
          type: "conversation.item.create",
          event_id: `tool_event_${this.counter}`,
          item: { id: itemId, type: "function_call_output", call_id: call.call_id, output: JSON.stringify(result) }
        });
        this.status(`Sent result for ${call.call_id}`);
      }
      p.timer = this.setTimer(() => this.fail("Tool output acknowledgement timed out"), 8000);
    } catch { this.fail("Could not send tool outputs"); }
  }
}

protocol-check.mjs

JavaScript
import assert from "node:assert/strict";
import { ToolController } from "./controller.mjs";

const deferred = () => { let resolve, reject; const promise = new Promise((a, b) => { resolve = a; reject = b; }); return { promise, resolve, reject }; };
const tick = () => new Promise(resolve => setImmediate(resolve));
const call = (id, name = "get_demo_hours") => ({ type: "function_call", status: "completed", call_id: id, name, arguments: "{}" });
const created = id => ({ type: "response.created", response: { id } });
const done = (id, status, output = []) => ({ type: "response.done", response: { id, status, output } });

function harness(runTool = async x => ({ ok: true, value: x.name })) {
  const sent = [], statuses = [], failures = [];
  const timers = new Map(); let nextTimer = 0;
  const controller = new ToolController({
    send: e => sent.push(e), runTool,
    status: s => statuses.push(s), fatal: e => failures.push(e),
    setTimer: callback => { const id = ++nextTimer; timers.set(id, callback); return id; },
    clearTimer: id => timers.delete(id)
  });
  return { controller, sent, statuses, failures, timers };
}

// Mixed audio/message output, two asynchronous calls resolved in reverse order.
{
  const a = deferred(), b = deferred();
  const h = harness(x => x.call_id === "call_A" ? a.promise : b.promise);
  await h.controller.handle(created("resp_1"));
  const work = h.controller.handle(done("resp_1", "completed", [
    { type: "message", status: "completed", content: [{ type: "output_audio", transcript: "Checking." }] },
    call("call_A"), call("call_B", "get_demo_address")
  ]));
  b.resolve({ ok: true, value: "address" }); await tick();
  assert.equal(h.sent.length, 0, "first finished lookup must not send or resume early");
  a.resolve({ ok: true, value: "hours" }); await work;
  assert.deepEqual(h.sent.map(x => x.item?.call_id), ["call_A", "call_B"]);
  assert.equal(h.sent.filter(x => x.type === "response.create").length, 0);
  await h.controller.handle({ type: "conversation.item.done", item: { id: h.sent[1].item.id } });
  assert.equal(h.sent.filter(x => x.type === "response.create").length, 0);
  await h.controller.handle({ type: "conversation.item.done", item: { id: h.sent[0].item.id } });
  assert.equal(h.sent.filter(x => x.type === "response.create").length, 1, "one resume after both item acknowledgements");
}

// One local lookup error does not erase the other result.
{
  const h = harness(async x => { if (x.call_id === "bad") throw Error("synthetic failure"); return { ok: true, value: "fixture" }; });
  await h.controller.handle(created("resp_2"));
  await h.controller.handle(done("resp_2", "completed", [call("bad"), call("good")]));
  assert.equal(JSON.parse(h.sent[0].item.output).ok, false);
  assert.equal(JSON.parse(h.sent[1].item.output).ok, true);
  for (const e of h.sent.slice()) await h.controller.handle({ type: "conversation.item.done", item: { id: e.item.id } });
  assert.equal(h.sent.filter(x => x.type === "response.create").length, 1);
}

// Partial/cancelled responses never dispatch a call.
for (const status of ["failed", "incomplete", "cancelled"]) {
  const h = harness();
  await h.controller.handle(created(`resp_${status}`));
  await h.controller.handle(done(`resp_${status}`, status, [call("ignored")]));
  assert.equal(h.sent.length, 0);
}

// Distinct rounds are bounded, and missing/duplicate IDs are rejected.
{
  const h = harness();
  for (let i = 1; i <= 3; i++) {
    await h.controller.handle(created(`round_${i}`));
    await h.controller.handle(done(`round_${i}`, "completed", [call(`call_${i}`)]));
    const last = h.sent.at(-1);
    await h.controller.handle({ type: "conversation.item.done", item: { id: last.item.id } });
  }
  await h.controller.handle(created("round_4"));
  await h.controller.handle(done("round_4", "completed", [call("too_many")]));
  assert.match(h.failures[0], /bound/);
  assert.equal(h.sent.filter(x => x.type === "response.create").length, 3);
}
{
  const h = harness();
  await h.controller.handle(created("dup"));
  await h.controller.handle(done("dup", "completed", [call("same"), call("same")]));
  assert.match(h.failures[0], /repeated/);
}

// User speech or Stop invalidates in-flight lookups and ignores their late results.
for (const mode of ["speech", "stop"]) {
  const d = deferred(), h = harness(() => d.promise);
  await h.controller.handle(created(`resp_${mode}`));
  const work = h.controller.handle(done(`resp_${mode}`, "completed", [call("late")]));
  if (mode === "speech") await h.controller.handle({ type: "input_audio_buffer.speech_started" });
  else h.controller.close();
  d.resolve({ ok: true, value: "late fixture" }); await work;
  assert.equal(h.sent.length, 0);
}

// A late response completion or acknowledgement from the interrupted turn cannot resume it.
{
  const h = harness();
  await h.controller.handle(created("old"));
  await h.controller.handle({ type: "input_audio_buffer.speech_started" });
  await h.controller.handle(done("old", "completed", [call("late_call")]));
  assert.equal(h.sent.length, 0);
  await h.controller.handle(created("new"));
  await h.controller.handle(done("new", "completed", [call("fresh_call")]));
  const output = h.sent[0];
  await h.controller.handle({ type: "input_audio_buffer.speech_started" });
  await h.controller.handle({ type: "conversation.item.done", item: { id: output.item.id } });
  assert.equal(h.sent.filter(x => x.type === "response.create").length, 0);
}

// Missing server acknowledgement closes instead of speculatively resuming.
{
  const h = harness();
  await h.controller.handle(created("no_ack"));
  await h.controller.handle(done("no_ack", "completed", [call("one")]));
  assert.equal(h.timers.size, 1);
  [...h.timers.values()][0]();
  assert.match(h.failures[0], /timed out/);
  assert.equal(h.sent.filter(x => x.type === "response.create").length, 0);
}

console.log("Synthetic controller checks passed: ordering, single resume, error isolation, bounds and interruption.");

browser-check.mjs

JavaScript
import assert from "node:assert/strict";
import fs from "node:fs";
import vm from "node:vm";
import { ToolController } from "./controller.mjs";

const html = fs.readFileSync(new URL("./index.html", import.meta.url), "utf8");
const script = html.match(/<script type="module">([\s\S]*?)<\/script>/)?.[1]
  .replace('import { ToolController } from "/controller.mjs";', "");
assert.ok(script, "inline browser module found");

function fakePage(mediaPromise) {
  const nodes = Object.fromEntries(["#start", "#stop", "#status", "#events", "#reply"].map(k => [k, {
    disabled: k === "#stop", textContent: "", srcObject: null,
    pause() { this.paused = true; }, play() { return Promise.resolve(); }
  }]));
  let fetches = 0, peer;
  class FakePeer {
    constructor() { peer = this; this.connectionState = "new"; }
    addTrack() {}
    createDataChannel() { return this.dc = { readyState: "open", close() { this.closed = true; }, send() {} }; }
    async createOffer() { return { sdp: "v=0" }; }
    async setLocalDescription() {}
    async setRemoteDescription() {}
    close() { this.closed = true; }
  }
  vm.runInNewContext(script, {
    ToolController, document: { querySelector: k => nodes[k] },
    navigator: { mediaDevices: { getUserMedia: () => mediaPromise } },
    RTCPeerConnection: FakePeer,
    fetch: async () => { fetches++; return { ok: true, text: async () => "answer" }; },
    window: { addEventListener() {} },
    AbortController, setTimeout, clearTimeout, console
  });
  return { nodes, peer: () => peer, fetches: () => fetches };
}

// Stop while permission is pending; any late track is released without a session request.
{
  let allowMic;
  const page = fakePage(new Promise(resolve => { allowMic = resolve; }));
  const starting = page.nodes["#start"].onclick();
  page.nodes["#stop"].onclick();
  const track = { stopped: false, stop() { this.stopped = true; } };
  allowMic({ getTracks: () => [track], getAudioTracks: () => [track] });
  await starting;
  assert.equal(track.stopped, true);
  assert.equal(page.fetches(), 0);
  assert.equal(page.nodes["#start"].disabled, false);
}

// Stop after signaling: microphone, data channel, peer and playback all close.
{
  const track = { stopped: false, stop() { this.stopped = true; } };
  const page = fakePage(Promise.resolve({ getTracks: () => [track], getAudioTracks: () => [track] }));
  await page.nodes["#start"].onclick();
  page.nodes["#stop"].onclick();
  assert.equal(page.fetches(), 1);
  assert.equal(track.stopped, true);
  assert.equal(page.peer().closed, true);
  assert.equal(page.peer().dc.closed, true);
  assert.equal(page.nodes["#reply"].paused, true);
  assert.equal(page.nodes["#reply"].srcObject, null);
}

console.log("Synthetic browser lifecycle checks passed: late microphone and full Stop cleanup.");

ఆ డైరెక్టరీలో సర్వర్‌కు ఉన్న ఒకే ఆధార ప్యాకేజీని ఇన్‌స్టాల్ చేసి సర్వర్ ప్రారంభించండి:

Terminal
npm init -y
npm install express
node server.mjs

తెరవండి http://localhost:3000. పేజీలో Start voice, Stop and release microphone, ఆడియో ప్లేయర్, సంఘటన స్థితి కనిపించాలి. బ్రౌజర్ పేజీ, కంట్రోలర్ మాడ్యూల్ మాత్రమే అందిస్తారు; రెండు పరీక్ష ఫంక్షన్లు బ్రౌజర్‌లో నడుస్తాయి, నిజమైన స్థలం, క్యాలెండర్, CRM లేదా వ్యాపార ఖాతాకు చేరవు.

2. ప్రారంభించి, విని, ఫలితం తనిఖీ చేయండి

క్లిక్ చేయండి Start voice, మైక్రోఫోన్ అనుమతించి Connected కోసం వేచి ఉండండి. కల్పిత ప్రదర్శన గ్రంథాలయ సమయాలు, చిరునామా అడగండి. బ్రౌజర్ WebRTC మీడియా ట్రాక్‌లో మైక్రోఫోన్ ధ్వని పంపి, దూరపు వాయిస్ ట్రాక్ రాగానే ఆడియో నియంత్రణకు జోడిస్తుంది. ఆటోప్లే ఆగితే కనిపించే నియంత్రణలో Play నొక్కండి. ఉపయోగకరమైతే ముందుగా చిన్న ప్రగతి మాట చెప్పాలని సర్వర్ సూచన అడుగుతుంది. మోడల్ దాన్ని వదిలేయవచ్చు; విన్నంత మాత్రాన శోధన విజయమని కాదు.

సంఘటన ప్యానెల్ కీ, ముడి ఆడియో, లిఖిత సంభాషణ చూపకుండా స్పందన స్థితులు, కాల్ IDలు, అవుట్‌పుట్ ధృవీకరణలు చూపిస్తుంది. మోడల్ సాధనాలు ఎంచుకోకపోవచ్చు, ఒకటి లేదా అనేకం ఎంచుకోవచ్చు. response.done లో status: completed ఉన్నప్పుడు కంట్రోలర్ అన్ని అవుట్‌పుట్ అంశాల్లో పూర్తయిన function_call అంశాలను వెతికి, ప్రతి call_id ఉందని, ప్రత్యేకమని తనిఖీ చేస్తుంది. అనుమతించిన శోధనలను పలు ఒకేసారి కూడా నడిపి, అసలు ID ఒక్కొక్కదానికి ఒక function_call_output పంపుతుంది. విఫల శోధన ఆ కాల్ దోష ఫలితం అవుతుంది, మిగతావి నిలుస్తాయి. ప్రతి కేటాయించిన అవుట్‌పుట్ అంశ ID కోసం conversation.item.done వచ్చే వరకు వేచి, తర్వాత ఒకే response.create పంపుతుంది. అన్ని ధృవీకరణల కోసం వేచి ఉండటం ఈ ఉదాహరణ జాగ్రత్త స్థానిక క్రమం, API నిబంధన కాదు. స్పందనకు గరిష్ఠం ఎనిమిది కాల్స్, అంతరాయం లేని ఒక సంభాషణ వంతుకు మూడు సాధన రౌండ్లు; ఇవి స్థానిక పరిమితులు.

గమనించండి Realtime session created, కనెక్టైన పీర్, ఉంటే టూల్ కాల్ IDలు, అవుట్‌పుట్ ధృవీకరణలు, పూర్తయిన తదుపరి స్పందన. సమాధానం విని సమయాలు, చిరునామాను index.html లోని కల్పిత స్ట్రింగ్‌లతో పోల్చండి. స్పందన పూర్తయిన సంఘటన మాత్రమే వినిపించే ప్లేబ్యాక్ లేదా సమాధాన సత్యాన్ని నిర్ధారించదు. ఈ పరిశీలనలకు మీ స్వంత బిల్లు వచ్చే బ్రౌజర్ నడుపుదల కావాలి; BIG CHANGE చేయలేదు.

3. మరో వంతు, మధ్యలో మాట్లాడటం, మైక్రోఫోన్ విడుదల పరీక్షించండి

మళ్లీ ప్రారంభించకుండా మరో ప్రశ్న అడగండి. మధ్యలో ఆపడం పరీక్షించేందుకు మోడల్ మాట్లాడుతున్నప్పుడు లేదా శోధన వేచి ఉన్నప్పుడు మాట్లాడండి. WebRTC, వాయిస్ కార్యకలాప గుర్తింపుతో OpenAI రద్దు, ఇంకా ప్లే కాని ఆడియోను సర్వర్ నియంత్రణలో కత్తిరించడం పత్రాల్లో వివరిస్తుంది. input_audio_buffer.speech_started వచ్చినప్పుడు స్థానిక కంట్రోలర్ వేచి ఉన్న శోధనలను కూడా చెల్లకుండా చేస్తుంది, కాబట్టి ఆలస్య ఫలితం ఆగిన స్పందనను మళ్లీ కొనసాగించలేదు. ఈ కోడ్ WebSocket ఆడియో ప్లేయర్‌కు కావాల్సిన వేరే ప్లేబ్యాక్ కర్సర్, కత్తిరింపు సంఘటనలు అమలు చేయదు.

క్లిక్ చేయండి Stop and release microphone; బ్రౌజర్ మైక్రోఫోన్ సూచిక ఆరిందని నిర్ధారించండి. అనుమతి అభ్యర్థన వేచి ఉన్నప్పుడూ ఆపవచ్చు; అనుమతి ఆలస్యంగా వస్తే పొందిన ట్రాక్ వెంటనే ఆగుతుంది. అదే శుభ్రపరచడం ట్రాక్‌లను ఆపి, ప్రస్తుత సెషన్ అభ్యర్థన రద్దుచేసి, డేటా ఛానల్, పీర్ మూసి, ప్లేబ్యాక్ నిలిపి విడదీసి, సాధన పనిని రద్దు చేస్తుంది. పేజీ విడిచేటప్పుడు, సెటప్ లేదా స్థానిక సెషన్ సమయం ముగిసినప్పుడు, కనెక్షన్ విఫలమైనప్పుడు టైమర్లు తొలగిస్తుంది. ఉదాహరణలో సెటప్ 30 సెకన్లు, స్థానిక సెషన్ 55 నిమిషాలు; OpenAI Realtime గరిష్ఠం 60 నిమిషాలంటుంది.

4. స్థానిక తనిఖీలు నడిపి వైఫల్యాలు సరిచేయండి

అదే డైరెక్టరీలో నడపండి:

Terminal
node --check server.mjs
node --check controller.mjs
node protocol-check.mjs
node browser-check.mjs

రెండు స్క్రిప్టులు కృత్రిమ సంఘటనలు, బ్రౌజర్ నమూనాలను వాడతాయి. సందేశం/ఫంక్షన్ కలిసిన స్పందన, తిరుగు క్రమంలో పూర్తయ్యే రెండు కాల్స్, ఒకే కొనసాగింపుకు ముందు అన్ని ఫలితాలు-ధృవీకరణలు, కాల్‌కు దోషాన్ని విడిగా ఉంచడం, పూర్తయినవి మాత్రమే నడపడం, రౌండ్ హద్దులు, మాటతో అంతరాయం, ఆలస్య అనుమతి విడుదల, Stop శుభ్రపరచడం తనిఖీ చేస్తాయి. API అభ్యర్థనలు చేయవు. ఉత్తీర్ణత నెట్‌వర్క్ సమయం, నిజమైన పరికరాలు, వాయిస్ నాణ్యత లేదా ఉత్పత్తి విశ్వసనీయతను కొలవదు.

ఒకవేళ Start విఫలమైతే కనిపించే స్థితి, స్థానిక సర్వర్‌కు అందిన ఎగువ HTTP స్థితి చదవండి. అనుమతి, localhost:3000, సర్వర్ వాతావరణ కీ, మోడల్ ప్రాప్యత, బిల్లింగ్, పరిమితులు, నెట్‌వర్క్ తనిఖీ చేయండి. 502 ఎగువ తిరస్కరణ, నెట్‌వర్క్ వైఫల్యం లేదా ఉదాహరణలో 25 సెకన్ల అభ్యర్థన గడువు వల్ల కావచ్చు; OpenAI అభ్యర్థన పొందలేదని నిరూపించదు. పీర్ కనెక్టై ధ్వని లేకపోతే ఇన్‌పుట్, అవుట్‌పుట్ పరికరాలు చూసి Play నొక్కండి. విఫల, అసంపూర్ణ, రద్దైన స్పందన పాక్షిక కాల్స్ నడపదు. అవుట్‌పుట్ ధృవీకరణ సమయం ముగిస్తే కంట్రోలర్ అనిశ్చిత రెండో కొనసాగింపు పంపకుండా సెషన్ మూస్తుంది. ప్రారంభం లేదా నెట్‌వర్క్ ఫలితం తెలియకపోతే సెషన్ ఆపి, మైక్రోఫోన్ విడుదల నిర్ధారించి, మళ్లీ ప్రయత్నించే ముందు ప్రాజెక్ట్ వినియోగం చూడండి; రద్దైన అభ్యర్థనకూ అప్పటికే ఖర్చు వచ్చి ఉండవచ్చు.

ఖర్చు, పరిమితులు

OpenAI అందించే మోడల్ పేజీ మరియు ధరల పట్టిక ను 2026 అక్టోబర్ 20న తనిఖీ చేశాం. కాష్ కాని టెక్స్ట్ ఇన్‌పుట్/అవుట్‌పుట్ పదిలక్షల టోకెన్లకు 4/24 అమెరికా డాలర్లు, ఆడియో ఇన్‌పుట్/అవుట్‌పుట్ 32/64 డాలర్లు. అసలు ఖర్చు టోకెన్లు, ఆడియో, పునరావృత సంభాషణ సందర్భంపై ఆధారపడుతుంది. బిల్లు, ఆలస్యం, ప్రత్యక్ష టూల్ ప్రవర్తన లేదా ప్రారంభ ప్రగతి మాటను కొలవలేదు. మైక్రోఫోన్ ధ్వని OpenAI కి పంపుతారు. స్థిర కల్పిత ఫంక్షన్లు నిజమైన వ్యాపార అనుసంధానాలు లేదా రాసే చర్యలను అనుమతించవు. భాగస్వామ్య అమలుకు స్వంత వినియోగదారు గుర్తింపు, హద్దులు, సాధన అనుమతి, పర్యవేక్షణ, సమీక్ష అవసరం.

మూలాలు, మరింత చదవడానికి

  • OpenAI WebRTC గైడ్: బ్రౌజర్ మీడియా ట్రాక్, దూరపు ప్లేబ్యాక్, డేటా ఛానల్, నమ్మదగిన సర్వర్ ద్వారా SDP మార్పిడి. ఈ నిర్దిష్ట బ్రౌజర్ లేదా ఖాతా పరీక్ష కాదు.
  • Realtime సంభాషణలు: పూర్తయిన స్పందన మొత్తం అవుట్‌పుట్, ఫంక్షన్ ఫలిత క్రమం, అంతరాయం, 60 నిమిషాల సరిహద్దు. ఒక మోడల్ టూల్ కాల్ చేస్తుందని హామీ లేదు.
  • Realtime సాధనాలు: అప్లికేషన్ బాధ్యతలో ఫంక్షన్ కాల్స్ మరియు function_call_output. స్థానిక పరీక్ష డేటా విజయం నిరూపించదు.
  • క్లయింట్ మరియు సర్వర్ సంఘటనలు సూచనలు: అంశ IDలు, ధృవీకరణ, స్పందన సంఘటన నిర్మాణాలు. అన్నింటికీ వేచి ఉండటం స్థానిక ఎంపిక.
  • Realtime సూచనలు రాయడం: షరతుతో చిన్న వాయిస్ ప్రగతి మాటకు మార్గదర్శనం; వినిపించే అవుట్‌పుట్ హామీ కాదు.
  • మోడల్ ప్రాప్యత మరియు API ధరలు: ప్రస్తుత ప్రాప్యత స్థాయులు, టోకెన్ రేట్లు. అసలు బిల్లుకు ప్రాజెక్ట్ వినియోగం చూడండి.