AI-translated from English; not yet reviewed by a fluent editor.
# सिर्फ़ पढ़ने वाले टूल कॉल के साथ स्थानीय Realtime वॉइस एजेंट बनाएँ
> OpenAI Realtime और दो काल्पनिक, सिर्फ़ पढ़ने वाले टूल से ब्राउज़र में लाइव आवाज़ की बातचीत बनाएँ। सर्वर, ब्राउज़र और कंट्रोलर का पूरा कोड कॉल ID मिलान, सुरक्षित जारी रखने, बीच में रोकने और माइक्रोफ़ोन मुक्त करने का तरीका दिखाता है।
By BIG CHANGE Editorial
Published: 2026-10-19T23:39:53.236Z
Updated: 2026-10-19T23:39:53.236Z
Canonical: https://bigchange.ai/blog/openai-realtime-voice-read-only-tool-calls-guide

AI-generated conceptual illustration by BIG CHANGE; no actual OpenAI interface, API session, device test or heard answer is depicted.
जब बोले गए जवाब के लिए कई खोजें चाहिए, तो ब्राउज़र की आवाज़ वाली बातचीत जटिल हो जाती है। मॉडल एक पूरे हुए जवाब में कई फ़ंक्शन कॉल लौटा सकता है। हर नतीजा उसकी मूल `call_id` के साथ वापस भेजना चाहिए और सारे नतीजे भेजने के बाद ही नया जवाब शुरू होना चाहिए। यह गाइड डेवलपर को पूरा localhost उदाहरण देता है: लाइव माइक्रोफ़ोन इनपुट, WebRTC स्ट्रीमिंग प्लेबैक, दो काल्पनिक सिर्फ़ पढ़ने वाले टूल, बार-बार संवाद और रुकावट पर सफ़ाई। यह हमारे [बुनियादी ब्राउज़र वॉइस गाइड](https://bigchange.ai/blog/openai-realtime-browser-voice-webrtc-guide) का विस्तार है, जो बाहरी टूल के बिना बोला गया जवाब बनाता है।
## बड़ा बदलाव
- **क्या बदला:** OpenAI का [Realtime API](https://developers.openai.com/api/docs/guides/realtime-conversations) लाइव वॉइस सत्र में फ़ंक्शन कॉल लौटा सकता है। यह उदाहरण `call_id` के ज़रिए पूरे कॉल को स्थानीय नतीजों से जोड़ता है, फिर मॉडल को आगे बढ़ने को कहता है।
- **यह क्यों महत्वपूर्ण है:** डेवलपर कई सिर्फ़ पढ़ने वाली खोजों पर निर्भर आवाज़ का जवाब जाँच सकता है। माइक्रोफ़ोन रिकॉर्डिंग और प्लेबैक ब्राउज़र में तथा सामान्य API कुंजी स्थानीय सर्वर पर रहती है।
- **किस पर नज़र रखें:** स्थानीय जाँचें कृत्रिम घटनाओं से घटना क्रम और सफ़ाई जाँचती हैं। आपके खाते, ब्राउज़र, उपकरण और नेटवर्क से सुनाई देने वाले, सही जवाब और अपेक्षित बिल मिलते हैं या नहीं, यह अपने सशुल्क सत्र में स्थापित करना होगा।
उदाहरण OpenAI का सामान्य Realtime WebRTC एंडपॉइंट `/v1/realtime/calls` और `gpt-realtime-2.1` इस्तेमाल करता है। यह अलग GPT-Live सत्र प्रोटोकॉल नहीं इस्तेमाल करता। नीचे के दो “पुस्तकालय” मान काल्पनिक सॉफ़्टवेयर जाँच डेटा हैं, किसी वास्तविक जगह की जानकारी नहीं। BIG CHANGE ने 20 अक्टूबर 2026 को मौजूदा [WebRTC](https://developers.openai.com/api/docs/guides/voice-webrtc), [बातचीत](https://developers.openai.com/api/docs/guides/realtime-conversations), [टूल](https://developers.openai.com/api/docs/guides/realtime-mcp) और [घटना](https://developers.openai.com/api/reference/resources/realtime/client-events) दस्तावेज़ जाँचे। हमने स्थानीय कृत्रिम कंट्रोलर और ब्राउज़र जाँचें चलाईं, पर सशुल्क API सत्र नहीं खोला, न वास्तविक माइक्रोफ़ोन रिकॉर्डिंग या आवाज़ जाँची।
## 1. पहुँच जाँचें और पाँच फ़ाइलें बनाएँ
आपको Node.js 22.6 या नया, माइक्रोफ़ोन और स्पीकर वाला मौजूदा ब्राउज़र, तथा `gpt-realtime-2.1` तक पहुँच वाला OpenAI API प्रोजेक्ट चाहिए। इसका [मॉडल पृष्ठ](https://developers.openai.com/api/docs/models/gpt-realtime-2.1) 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.");
```
उसी डायरेक्टरी में सर्वर की एकमात्र निर्भरता इंस्टॉल करें और सर्वर चलाएँ:
```bash
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. स्थानीय जाँचें चलाएँ और विफलताएँ सुधारें
उसी डायरेक्टरी में चलाएँ:
```bash
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 का [मॉडल पृष्ठ](https://developers.openai.com/api/docs/models/gpt-realtime-2.1) और [मूल्य तालिका](https://developers.openai.com/api/docs/pricing), 20 अक्टूबर 2026 को जाँचे गए, बिना कैश पाठ इनपुट/आउटपुट के लिए प्रति दस लाख टोकन 4/24 अमेरिकी डॉलर तथा ऑडियो इनपुट/आउटपुट के लिए 32/64 डॉलर बताते हैं। असली खर्च टोकन, ऑडियो और दोहराए गए बातचीत संदर्भ पर निर्भर है। हमने बिल, विलंब, लाइव टूल व्यवहार या शुरुआती प्रगति सूचना नहीं मापी। माइक्रोफ़ोन आवाज़ OpenAI को भेजी जाती है। तय काल्पनिक फ़ंक्शन असली व्यावसायिक एकीकरण या लिखने की कार्रवाई की अनुमति नहीं देते। साझा सेवा में अपनी उपयोगकर्ता पहचान, सीमाएँ, टूल अनुमति, निगरानी और समीक्षा चाहिए।
### स्रोत और आगे पढ़ें
- [OpenAI WebRTC गाइड](https://developers.openai.com/api/docs/guides/voice-webrtc): ब्राउज़र मीडिया ट्रैक, दूर का प्लेबैक, डेटा चैनल और भरोसेमंद सर्वर से SDP आदान-प्रदान। यह इस खास ब्राउज़र या खाते का परीक्षण नहीं है।
- [Realtime बातचीत](https://developers.openai.com/api/docs/guides/realtime-conversations): पूरे जवाब का पूरा आउटपुट, फ़ंक्शन परिणाम क्रम, रुकावट और 60 मिनट की सत्र सीमा। किसी खास मॉडल के टूल बुलाने का वादा नहीं।
- [Realtime टूल](https://developers.openai.com/api/docs/guides/realtime-mcp): ऐप के नियंत्रण वाले फ़ंक्शन कॉल और `function_call_output`। यह स्थानीय परीक्षण डेटा की सफलता साबित नहीं करता।
- [क्लाइंट](https://developers.openai.com/api/reference/resources/realtime/client-events) और [सर्वर घटनाएँ](https://developers.openai.com/api/reference/resources/realtime/server-events) संदर्भ: आइटम ID, पुष्टि और जवाब घटना संरचनाएँ। सभी पुष्टियों की प्रतीक्षा उदाहरण का स्थानीय चयन है।
- [Realtime के लिए निर्देश लिखना](https://developers.openai.com/api/docs/guides/voice-prompting): शर्त के अनुसार बोलकर छोटी प्रगति सूचना देने की सलाह; सुनाई देने वाले आउटपुट की गारंटी नहीं।
- [मॉडल पहुँच](https://developers.openai.com/api/docs/models/gpt-realtime-2.1) और [API कीमतें](https://developers.openai.com/api/docs/pricing): मौजूदा पहुँच स्तर और टोकन दरें। असली बिल के लिए अपना प्रोजेक्ट उपयोग देखें।
## Sources
- [OpenAI WebRTC गाइड](https://developers.openai.com/api/docs/guides/voice-webrtc) — ब्राउज़र माइक्रोफ़ोन व दूर के ऑडियो ट्रैक, oai-events डेटा चैनल और /v1/realtime/calls से मानक API कुंजी के साथ भरोसेमंद सर्वर SDP आदान-प्रदान बताता है। यह उदाहरण के असली उपकरण या नेटवर्क व्यवहार का प्रमाण नहीं।
- [OpenAI Realtime बातचीत](https://developers.openai.com/api/docs/guides/realtime-conversations) — response.done का पूरा आउटपुट, फ़ंक्शन परिणाम बाद जारी रखना, न चले ऑडियो को सर्वर से काटने वाला WebRTC VAD अवरोध और 60 मिनट सीमा बताता है। पाठक रन में टूल या सही बोली की गारंटी नहीं।
- [टूल के साथ OpenAI Realtime](https://developers.openai.com/api/docs/guides/realtime-mcp) — ऐप-नियंत्रित फ़ंक्शन टूल, मूल call_id वाले function_call_output आइटम और response.create से जारी रखना बताता है। हर आउटपुट पुष्टि की प्रतीक्षा अतिरिक्त स्थानीय क्रम है।
- [OpenAI Realtime क्लाइंट घटनाएँ](https://developers.openai.com/api/reference/resources/realtime/client-events) — उदाहरण के conversation.item.create, आइटम ID, function_call_output और response.create संरचनाएँ परिभाषित करता है; संदर्भ एकीकरण परीक्षण नहीं है।
- [OpenAI Realtime सर्वर घटनाएँ](https://developers.openai.com/api/reference/resources/realtime/server-events) — उदाहरण के पूरे जवाब, अंतिम बातचीत आइटम पुष्टि और त्रुटि घटनाएँ परिभाषित करता है। सभी पुष्टियों की प्रतीक्षा स्थानीय विकल्प है, API शर्त या एकीकरण परीक्षण नहीं।
- [OpenAI आवाज़ गतिविधि पहचान](https://developers.openai.com/api/docs/guides/realtime-vad) — स्थानीय काम अमान्य करने वाले speech_started और speech_stopped बताता है; यहाँ असली रुकावट नहीं जाँची गई।
- [OpenAI Realtime के लिए निर्देश लिखना](https://developers.openai.com/api/docs/guides/voice-prompting) — छोटी सशर्त प्रगति सूचना माँगने का समर्थन। सशुल्क सत्र में कोई सूचना देखी नहीं गई।
- [OpenAI gpt-realtime-2.1 मॉडल](https://developers.openai.com/api/docs/models/gpt-realtime-2.1) — मॉडल ID, असमर्थित Free स्तर और प्रति दस लाख टोकन बिना कैश दरें बताता है: पाठ इनपुट/आउटपुट 4/24 अमेरिकी डॉलर, ऑडियो इनपुट/आउटपुट 32/64। पाठक को खाते की पहुँच और बिलिंग जाँचनी होगी।
- [OpenAI API कीमतें](https://developers.openai.com/api/docs/pricing) — gpt-realtime-2.1 के प्रकाशित पाठ और ऑडियो टोकन मूल्य की पुष्टि; इस गाइड के सत्र की तय कीमत नहीं देता।
- [OpenAI API और ChatGPT बिलिंग](https://help.openai.com/en/articles/9039756-managing-billing-for-chatgpt-and-the-api-platform) — OpenAI कहता है कि API उपयोग की बिलिंग ChatGPT सदस्यता से अलग है। इससे पाठक का मौजूदा बैलेंस या प्रोजेक्ट सीमा स्थापित नहीं होती।
BIG CHANGE न्यूज़लेटर
बड़ी तस्वीर। आपकी गति से।
AI और रोबोटिक्स पर ताज़ा लेख, ध्यान देने योग्य बदलाव और उपयोगी विचार। दैनिक ब्रीफ़िंग, साप्ताहिक सारांश या मासिक परिप्रेक्ष्य चुनें।
Next scheduled send (UTC): . Your first edition arrives at the next scheduled send after you confirm.
आपकी गोपनीयता, आपकी पसंद।
ज़रूरी स्टोरेज साइट की सुरक्षा में मदद करता है और आपकी पसंद याद रखता है। आपकी अनुमति मिलने तक वैकल्पिक Google Analytics बंद रहता है। आप हर लेख केवल आवश्यक स्टोरेज के साथ पढ़ सकते हैं। गोपनीयता का विवरण