[{"data":1,"prerenderedAt":436},["ShallowReactive",2],{"navigation":3,"\u002Fdocs\u002Fguides":235,"surround-\u002Fdocs\u002Fguides":433},[4],{"title":5,"path":6,"stem":7,"children":8,"page":18},"Docs","\u002Fdocs","docs",[9,33,68,95,130,161,208],{"title":10,"path":11,"stem":12,"children":13,"page":18,"type":32},"Start","\u002Fdocs\u002Fstart","docs\u002F1.start",[14,20,24,28],{"title":15,"path":16,"stem":17,"new":18,"type":19,"children":-1},"Get started with Lanson Live API","\u002Fdocs\u002Fstart\u002Fquickstart","docs\u002F1.start\u002F2.quickstart",false,"page",{"title":21,"path":22,"stem":23,"new":18,"type":19,"children":-1},"Authentication","\u002Fdocs\u002Fstart\u002Fauthentication","docs\u002F1.start\u002F3.authentication",{"title":25,"path":26,"stem":27,"new":18,"type":19,"children":-1},"Choose an API","\u002Fdocs\u002Fstart\u002Fchoose-an-api","docs\u002F1.start\u002F5.choose-an-api",{"title":29,"path":30,"stem":31,"new":18,"type":19,"children":-1},"Pricing","\u002Fdocs\u002Fstart\u002Fpricing","docs\u002F1.start\u002F6.pricing","group",{"title":34,"path":35,"stem":36,"children":37,"new":18,"type":32},"Realtime","\u002Fdocs\u002Frealtime","docs\u002F2.realtime\u002F1.index",[38,40,44,48,52,56,60,64],{"title":39,"path":35,"stem":36,"new":18,"type":19,"children":-1},"Realtime Overview",{"title":41,"path":42,"stem":43,"new":18,"type":19,"children":-1},"Realtime Quickstart","\u002Fdocs\u002Frealtime\u002Fquickstart","docs\u002F2.realtime\u002F2.quickstart",{"title":45,"path":46,"stem":47,"new":18,"type":19,"children":-1},"Connection Lifecycle","\u002Fdocs\u002Frealtime\u002Fconnection-lifecycle","docs\u002F2.realtime\u002F3.connection-lifecycle",{"title":49,"path":50,"stem":51,"new":18,"type":19,"children":-1},"Audio Input","\u002Fdocs\u002Frealtime\u002Faudio-input","docs\u002F2.realtime\u002F4.audio-input",{"title":53,"path":54,"stem":55,"new":18,"type":19,"children":-1},"Transcript Lifecycle","\u002Fdocs\u002Frealtime\u002Ftranscript-lifecycle","docs\u002F2.realtime\u002F5.transcript-lifecycle",{"title":57,"path":58,"stem":59,"new":18,"type":19,"children":-1},"Realtime Translation","\u002Fdocs\u002Frealtime\u002Frealtime-translation","docs\u002F2.realtime\u002F6.realtime-translation",{"title":61,"path":62,"stem":63,"new":18,"type":19,"children":-1},"Session Configuration","\u002Fdocs\u002Frealtime\u002Fsession-configuration","docs\u002F2.realtime\u002F7.session-configuration",{"title":65,"path":66,"stem":67,"new":18,"type":19,"children":-1},"Handling Interruptions & Silence","\u002Fdocs\u002Frealtime\u002Finterruptions-silence","docs\u002F2.realtime\u002F8.interruptions-silence",{"title":69,"path":70,"stem":71,"children":72,"new":18,"type":32},"Recorded","\u002Fdocs\u002Frecorded","docs\u002F3.recorded\u002F1.index",[73,75,79,83,87,91],{"title":74,"path":70,"stem":71,"new":18,"type":19,"children":-1},"Recorded Overview",{"title":76,"path":77,"stem":78,"new":18,"type":19,"children":-1},"Transcribe Audio","\u002Fdocs\u002Frecorded\u002Ftranscribe-audio","docs\u002F3.recorded\u002F2.transcribe-audio",{"title":80,"path":81,"stem":82,"new":18,"type":19,"children":-1},"Timestamps & Speakers","\u002Fdocs\u002Frecorded\u002Ftimestamps-speakers","docs\u002F3.recorded\u002F3.timestamps-speakers",{"title":84,"path":85,"stem":86,"new":18,"type":19,"children":-1},"Subtitles","\u002Fdocs\u002Frecorded\u002Fsubtitles","docs\u002F3.recorded\u002F4.subtitles",{"title":88,"path":89,"stem":90,"new":18,"type":19,"children":-1},"Recorded Translation","\u002Fdocs\u002Frecorded\u002Ftranslation","docs\u002F3.recorded\u002F5.translation",{"title":92,"path":93,"stem":94,"new":18,"type":19,"children":-1},"Structured Results","\u002Fdocs\u002Frecorded\u002Fstructured-results","docs\u002F3.recorded\u002F6.structured-results",{"title":96,"path":97,"stem":98,"children":99,"new":18,"type":32},"Concepts","\u002Fdocs\u002Fconcepts","docs\u002F4.concepts\u002F1.index",[100,102,106,110,114,118,122,126],{"title":101,"path":97,"stem":98,"new":18,"type":19,"children":-1},"Voice Context Layer",{"title":103,"path":104,"stem":105,"new":18,"type":19,"children":-1},"Stable vs. Partial Text","\u002Fdocs\u002Fconcepts\u002Fstable-vs-partial-text","docs\u002F4.concepts\u002F2.stable-vs-partial-text",{"title":107,"path":108,"stem":109,"new":18,"type":19,"children":-1},"StableStream™","\u002Fdocs\u002Fconcepts\u002Fstablestream","docs\u002F4.concepts\u002F3.stablestream",{"title":111,"path":112,"stem":113,"new":18,"type":19,"children":-1},"Context-Aware Processing","\u002Fdocs\u002Fconcepts\u002Fcontext-aware-processing","docs\u002F4.concepts\u002F4.context-aware-processing",{"title":115,"path":116,"stem":117,"new":18,"type":19,"children":-1},"Understanding Latency","\u002Fdocs\u002Fconcepts\u002Flatency","docs\u002F4.concepts\u002F5.latency",{"title":119,"path":120,"stem":121,"new":18,"type":19,"children":-1},"Live Translation","\u002Fdocs\u002Fconcepts\u002Flive-translation","docs\u002F4.concepts\u002F6.live-translation",{"title":123,"path":124,"stem":125,"new":18,"type":19,"children":-1},"Trinity Engine","\u002Fdocs\u002Fconcepts\u002Ftrinity-engine","docs\u002F4.concepts\u002F7.trinity-engine",{"title":127,"path":128,"stem":129,"new":18,"type":19,"children":-1},"LiveFinal™","\u002Fdocs\u002Fconcepts\u002Flivefinal","docs\u002F4.concepts\u002F8.livefinal",{"title":131,"path":132,"stem":133,"children":134,"new":18,"type":32},"Guides","\u002Fdocs\u002Fguides","docs\u002F5.guides\u002F1.index",[135,137,141,145,149,153,157],{"title":136,"path":132,"stem":133,"new":18,"type":19,"children":-1},"Browser Live Captions",{"title":138,"path":139,"stem":140,"new":18,"type":19,"children":-1},"Server-side Streaming","\u002Fdocs\u002Fguides\u002Fserver-side-streaming","docs\u002F5.guides\u002F2.server-side-streaming",{"title":142,"path":143,"stem":144,"new":18,"type":19,"children":-1},"Build a Stable Caption UI","\u002Fdocs\u002Fguides\u002Fstable-caption-ui","docs\u002F5.guides\u002F3.stable-caption-ui",{"title":146,"path":147,"stem":148,"new":18,"type":19,"children":-1},"Build Live Translation","\u002Fdocs\u002Fguides\u002Flive-translation","docs\u002F5.guides\u002F4.live-translation",{"title":150,"path":151,"stem":152,"new":18,"type":19,"children":-1},"Save a Transcript","\u002Fdocs\u002Fguides\u002Fsave-transcript","docs\u002F5.guides\u002F5.save-transcript",{"title":154,"path":155,"stem":156,"new":18,"type":19,"children":-1},"Reconnect a Live Session","\u002Fdocs\u002Fguides\u002Freconnection","docs\u002F5.guides\u002F6.reconnection",{"title":158,"path":159,"stem":160,"new":18,"type":19,"children":-1},"Client-VAD speech segments","\u002Fdocs\u002Fguides\u002Fclient-vad-segments","docs\u002F5.guides\u002F7.client-vad-segments",{"title":162,"path":163,"stem":164,"children":165,"new":18,"type":32},"API Reference","\u002Fdocs\u002Fapi-reference","docs\u002F6.api-reference\u002F1.index",[166,168,172,176,180,184,188,192,196,200,204],{"title":167,"path":163,"stem":164,"new":18,"type":19,"children":-1},"API Reference Overview",{"title":169,"path":170,"stem":171,"new":18,"type":19,"children":-1},"Realtime API","\u002Fdocs\u002Fapi-reference\u002Frealtime-api","docs\u002F6.api-reference\u002F2.realtime-api",{"title":173,"path":174,"stem":175,"new":18,"type":19,"children":-1},"Client Messages","\u002Fdocs\u002Fapi-reference\u002Fclient-messages","docs\u002F6.api-reference\u002F3.client-messages",{"title":177,"path":178,"stem":179,"new":18,"type":19,"children":-1},"Server Events","\u002Fdocs\u002Fapi-reference\u002Fserver-events","docs\u002F6.api-reference\u002F4.server-events",{"title":181,"path":182,"stem":183,"new":18,"type":19,"children":-1},"Segment Transcription API","\u002Fdocs\u002Fapi-reference\u002Fsegment-transcription","docs\u002F6.api-reference\u002F5.segment-transcription",{"title":185,"path":186,"stem":187,"new":18,"type":19,"children":-1},"Batch Transcription Jobs","\u002Fdocs\u002Fapi-reference\u002Fbatch-jobs","docs\u002F6.api-reference\u002F6.batch-jobs",{"title":189,"path":190,"stem":191,"new":18,"type":19,"children":-1},"Languages & Models","\u002Fdocs\u002Fapi-reference\u002Flanguages","docs\u002F6.api-reference\u002F7.languages",{"title":193,"path":194,"stem":195,"new":18,"type":19,"children":-1},"Errors","\u002Fdocs\u002Fapi-reference\u002Ferrors","docs\u002F6.api-reference\u002F8.errors",{"title":197,"path":198,"stem":199,"new":18,"type":19,"children":-1},"Rate Limits","\u002Fdocs\u002Fapi-reference\u002Frate-limits","docs\u002F6.api-reference\u002F9.rate-limits",{"title":201,"path":202,"stem":203,"new":18,"type":19,"children":-1},"Admin API","\u002Fdocs\u002Fapi-reference\u002Fadmin","docs\u002F6.api-reference\u002F10.admin",{"title":205,"path":206,"stem":207,"new":18,"type":19,"children":-1},"Language Detection","\u002Fdocs\u002Fapi-reference\u002Flanguage-detection","docs\u002F6.api-reference\u002F11.language-detection",{"title":209,"path":210,"stem":211,"children":212,"new":18,"type":32},"Production","\u002Fdocs\u002Fproduction","docs\u002F7.production\u002F1.index",[213,215,219,223,227,231],{"title":214,"path":210,"stem":211,"new":18,"type":19,"children":-1},"Production Checklist",{"title":216,"path":217,"stem":218,"new":18,"type":19,"children":-1},"Reconnection & Retries","\u002Fdocs\u002Fproduction\u002Freconnection-retries","docs\u002F7.production\u002F2.reconnection-retries",{"title":220,"path":221,"stem":222,"new":18,"type":19,"children":-1},"Latency Best Practices","\u002Fdocs\u002Fproduction\u002Flatency-best-practices","docs\u002F7.production\u002F3.latency-best-practices",{"title":224,"path":225,"stem":226,"new":18,"type":19,"children":-1},"Security & Privacy","\u002Fdocs\u002Fproduction\u002Fsecurity-privacy","docs\u002F7.production\u002F4.security-privacy",{"title":228,"path":229,"stem":230,"new":18,"type":19,"children":-1},"Data Retention","\u002Fdocs\u002Fproduction\u002Fdata-retention","docs\u002F7.production\u002F5.data-retention",{"title":232,"path":233,"stem":234,"new":18,"type":19,"children":-1},"Changelog","\u002Fdocs\u002Fproduction\u002Fchangelog","docs\u002F7.production\u002F6.changelog",{"id":236,"title":136,"body":237,"description":424,"extension":425,"links":426,"meta":427,"navigation":429,"new":18,"path":132,"rawbody":430,"seo":431,"stem":133,"technology":426,"__hash__":432},"content\u002Fdocs\u002F5.guides\u002F1.index.md",{"type":238,"value":239,"toc":414},"minimark",[240,244,249,256,260,263,274,286,290,296,326,330,336,343,349,353,359,363,393,397],[241,242,243],"p",{},"Build a browser-based live caption interface using the LansonAI realtime API.",[245,246,248],"h2",{"id":247},"architecture","Architecture",[241,250,251],{},[252,253],"img",{"alt":254,"src":255},"Browser Live Captions Architecture","\u002Fimages\u002Fdocs\u002Fbrowser-live-captions-flow.png",[245,257,259],{"id":258},"step-1-get-a-session-token","Step 1: Get a session token",[241,261,262],{},"Your backend exchanges the long-lived API key for a 60-second session token:",[264,265,271],"pre",{"className":266,"code":268,"language":269,"meta":270},[267],"language-javascript","\u002F\u002F backend route\napp.post('\u002Fsession-token', async (req, res) => {\n  const resp = await fetch('https:\u002F\u002Faudio.lansonai.com\u002Fv1\u002Faudio\u002Ftranscriptions\u002Fsession-token', {\n    method: 'POST',\n    headers: { Authorization: `Bearer ${process.env.LANSON_AUDIO_API_KEY}` },\n  });\n  res.json(await resp.json());\n});\n","javascript","",[272,273,268],"code",{"__ignoreMap":270},[275,276,279],"callout",{"color":277,"icon":278},"amber","i-lucide-triangle-alert",[241,280,281,282,285],{},"Never expose ",[272,283,284],{},"sk-..."," in frontend code. Always proxy through your backend.",[245,287,289],{"id":288},"step-2-open-websocket","Step 2: Open WebSocket",[264,291,294],{"className":292,"code":293,"language":269,"meta":270},[267],"const { token } = await fetch('\u002Fsession-token', { method: 'POST' }).then(r => r.json());\nconst ws = new WebSocket(\n  `wss:\u002F\u002Faudio.lansonai.com\u002Fv1\u002Faudio\u002Ftranscriptions\u002Fstream?access_token=${token}`\n);\nawait new Promise((resolve) => { ws.onopen = resolve; });\n",[272,295,293],{"__ignoreMap":270},[275,297,300],{"color":298,"icon":299},"primary","i-lucide-info",[241,301,302,310,311,314,315,321,322,325],{},[303,304,305,306,309],"strong",{},"Passing ",[272,307,308],{},"language"," is recommended when you know it",", because it improves accuracy. If you do not know it, omit it or send ",[272,312,313],{},"language: \"auto\""," and the service auto-detects it. You can also call ",[316,317,318],"a",{"href":206},[272,319,320],{},"\u002Fv1\u002Faudio\u002Flanguage-detection"," first and pass the result. When the language changes mid-session, send ",[272,323,324],{},"\"auto\""," again to re-detect; an explicit code always wins.",[245,327,329],{"id":328},"step-3-capture-and-send-audio","Step 3: Capture and send audio",[264,331,334],{"className":332,"code":333,"language":269,"meta":270},[267],"\u002F\u002F Convert an ArrayBuffer of PCM16LE to base64\nfunction toBase64(buffer) {\n  const bytes = new Uint8Array(buffer);\n  let binary = '';\n  for (let i = 0; i \u003C bytes.length; i++) binary += String.fromCharCode(bytes[i]);\n  return btoa(binary);\n}\n\nconst audioContext = new AudioContext({ sampleRate: 16000 });\nconst stream = await navigator.mediaDevices.getUserMedia({ audio: true });\nconst source = audioContext.createMediaStreamSource(stream);\n\n\u002F\u002F Recommended: set the audio language before sending frames\nws.send(JSON.stringify({ type: 'session.update', language: 'en' }));\n\n\u002F\u002F Use AudioWorklet to get PCM16LE frames\nawait audioContext.audioWorklet.addModule('pcm-processor.js');\nconst node = new AudioWorkletNode(audioContext, 'pcm-processor');\nsource.connect(node);\n\n\u002F\u002F pcm-processor.js posts PCM16LE buffers to main thread\nnode.port.onmessage = (e) => {\n  \u002F\u002F Send base64 JSON frames (binary frames are not transcribed today)\n  ws.send(JSON.stringify({\n    type: 'input_audio_buffer.append',\n    audio: toBase64(e.data),\n  }));\n};\n",[272,335,333],{"__ignoreMap":270},[241,337,338,339,342],{},"Minimal ",[272,340,341],{},"pcm-processor.js",":",[264,344,347],{"className":345,"code":346,"language":269,"meta":270},[267],"class PcmProcessor extends AudioWorkletProcessor {\n  process(inputs) {\n    const input = inputs[0][0]; \u002F\u002F mono, 16kHz\n    if (input) {\n      const pcm16 = new Int16Array(input.length);\n      for (let i = 0; i \u003C input.length; i++) {\n        const s = Math.max(-1, Math.min(1, input[i]));\n        pcm16[i] = s \u003C 0 ? s * 0x8000 : s * 0x7fff;\n      }\n      this.port.postMessage(pcm16.buffer);\n    }\n    return true;\n  }\n}\nregisterProcessor('pcm-processor', PcmProcessor);\n",[272,348,346],{"__ignoreMap":270},[245,350,352],{"id":351},"step-4-display-captions","Step 4: Display captions",[264,354,357],{"className":355,"code":356,"language":269,"meta":270},[267],"ws.onmessage = (event) => {\n  const data = JSON.parse(event.data);\n  if (data.type === 'conversation.item.input_audio_transcription.completed') {\n    const div = document.getElementById('captions');\n    const p = document.createElement('p');\n    p.textContent = data.text;\n    div.appendChild(p);\n  }\n};\n",[272,358,356],{"__ignoreMap":270},[245,360,362],{"id":361},"browser-security","Browser security",[364,365,366,376,383,386],"ul",{},[367,368,369,372,373,375],"li",{},[303,370,371],{},"Never"," put ",[272,374,284],{}," in frontend code",[367,377,378,379,382],{},"Always obtain ",[272,380,381],{},"rt_..."," tokens from your backend",[367,384,385],{},"Tokens expire in 60 seconds — get a fresh one for each connection",[367,387,388,389,392],{},"WebSocket ",[272,390,391],{},"?access_token"," keeps the long-lived key off the client",[245,394,396],{"id":395},"related","Related",[364,398,399,404,409],{},[367,400,401,403],{},[316,402,142],{"href":143}," — advanced UI patterns",[367,405,406,408],{},[316,407,21],{"href":22}," — session token details",[367,410,411,413],{},[316,412,41],{"href":42}," — more examples",{"title":270,"searchDepth":415,"depth":415,"links":416},2,[417,418,419,420,421,422,423],{"id":247,"depth":415,"text":248},{"id":258,"depth":415,"text":259},{"id":288,"depth":415,"text":289},{"id":328,"depth":415,"text":329},{"id":351,"depth":415,"text":352},{"id":361,"depth":415,"text":362},{"id":395,"depth":415,"text":396},"Browser microphone → Lanson → caption UI.","md",null,{"updated":428},"2026-11-08",true,"---\ntitle: Browser Live Captions\nupdated: 2026-11-08\ndescription: Browser microphone → Lanson → caption UI.\n---\n\nBuild a browser-based live caption interface using the LansonAI realtime API.\n\n## Architecture\n\n![Browser Live Captions Architecture](\u002Fimages\u002Fdocs\u002Fbrowser-live-captions-flow.png)\n\n## Step 1: Get a session token\n\nYour backend exchanges the long-lived API key for a 60-second session token:\n\n```javascript\n\u002F\u002F backend route\napp.post('\u002Fsession-token', async (req, res) => {\n  const resp = await fetch('https:\u002F\u002Faudio.lansonai.com\u002Fv1\u002Faudio\u002Ftranscriptions\u002Fsession-token', {\n    method: 'POST',\n    headers: { Authorization: `Bearer ${process.env.LANSON_AUDIO_API_KEY}` },\n  });\n  res.json(await resp.json());\n});\n```\n\n::callout{icon=\"i-lucide-triangle-alert\" color=\"amber\"}\nNever expose `sk-...` in frontend code. Always proxy through your backend.\n::\n\n## Step 2: Open WebSocket\n\n```javascript\nconst { token } = await fetch('\u002Fsession-token', { method: 'POST' }).then(r => r.json());\nconst ws = new WebSocket(\n  `wss:\u002F\u002Faudio.lansonai.com\u002Fv1\u002Faudio\u002Ftranscriptions\u002Fstream?access_token=${token}`\n);\nawait new Promise((resolve) => { ws.onopen = resolve; });\n```\n\n::callout{icon=\"i-lucide-info\" color=\"primary\"}\n**Passing `language` is recommended when you know it**, because it improves accuracy. If you do not know it, omit it or send `language: \"auto\"` and the service auto-detects it. You can also call [`\u002Fv1\u002Faudio\u002Flanguage-detection`](\u002Fdocs\u002Fapi-reference\u002Flanguage-detection) first and pass the result. When the language changes mid-session, send `\"auto\"` again to re-detect; an explicit code always wins.\n::\n\n## Step 3: Capture and send audio\n\n```javascript\n\u002F\u002F Convert an ArrayBuffer of PCM16LE to base64\nfunction toBase64(buffer) {\n  const bytes = new Uint8Array(buffer);\n  let binary = '';\n  for (let i = 0; i \u003C bytes.length; i++) binary += String.fromCharCode(bytes[i]);\n  return btoa(binary);\n}\n\nconst audioContext = new AudioContext({ sampleRate: 16000 });\nconst stream = await navigator.mediaDevices.getUserMedia({ audio: true });\nconst source = audioContext.createMediaStreamSource(stream);\n\n\u002F\u002F Recommended: set the audio language before sending frames\nws.send(JSON.stringify({ type: 'session.update', language: 'en' }));\n\n\u002F\u002F Use AudioWorklet to get PCM16LE frames\nawait audioContext.audioWorklet.addModule('pcm-processor.js');\nconst node = new AudioWorkletNode(audioContext, 'pcm-processor');\nsource.connect(node);\n\n\u002F\u002F pcm-processor.js posts PCM16LE buffers to main thread\nnode.port.onmessage = (e) => {\n  \u002F\u002F Send base64 JSON frames (binary frames are not transcribed today)\n  ws.send(JSON.stringify({\n    type: 'input_audio_buffer.append',\n    audio: toBase64(e.data),\n  }));\n};\n```\n\nMinimal `pcm-processor.js`:\n\n```javascript\nclass PcmProcessor extends AudioWorkletProcessor {\n  process(inputs) {\n    const input = inputs[0][0]; \u002F\u002F mono, 16kHz\n    if (input) {\n      const pcm16 = new Int16Array(input.length);\n      for (let i = 0; i \u003C input.length; i++) {\n        const s = Math.max(-1, Math.min(1, input[i]));\n        pcm16[i] = s \u003C 0 ? s * 0x8000 : s * 0x7fff;\n      }\n      this.port.postMessage(pcm16.buffer);\n    }\n    return true;\n  }\n}\nregisterProcessor('pcm-processor', PcmProcessor);\n```\n\n## Step 4: Display captions\n\n```javascript\nws.onmessage = (event) => {\n  const data = JSON.parse(event.data);\n  if (data.type === 'conversation.item.input_audio_transcription.completed') {\n    const div = document.getElementById('captions');\n    const p = document.createElement('p');\n    p.textContent = data.text;\n    div.appendChild(p);\n  }\n};\n```\n\n## Browser security\n\n- **Never** put `sk-...` in frontend code\n- Always obtain `rt_...` tokens from your backend\n- Tokens expire in 60 seconds — get a fresh one for each connection\n- WebSocket `?access_token` keeps the long-lived key off the client\n\n## Related\n\n- [Build a Stable Caption UI](\u002Fdocs\u002Fguides\u002Fstable-caption-ui) — advanced UI patterns\n- [Authentication](\u002Fdocs\u002Fstart\u002Fauthentication) — session token details\n- [Realtime Quickstart](\u002Fdocs\u002Frealtime\u002Fquickstart) — more examples\n",{"title":136,"description":424},"WmIL1FrWll9m1IVAbaNeD9yN0YIPbDxywNxXmAzhsG0",[434,435],{"title":127,"path":128,"stem":129,"children":-1},{"title":138,"path":139,"stem":140,"children":-1},1795064383654]