惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
博客园_首页
美团技术团队
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
J
Java Code Geeks
T
Tailwind CSS Blog
Jina AI
Jina AI
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
Google Developers Blog
爱范儿
爱范儿
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
小众软件
小众软件
MongoDB | Blog
MongoDB | Blog
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
perf(voice-call): trim realtime audio copies · openclaw/o...
scoootscooob · 2026-05-04 · via Recent Commits to openclaw:main

@@ -50,6 +50,11 @@ const MAX_PENDING_AUDIO_CHUNKS = 320;

5050

const DEFAULT_AUDIO_STREAM_END_SILENCE_MS = 500;

5151

const GOOGLE_REALTIME_BROWSER_SESSION_TTL_MS = 30 * 60 * 1000;

5252

const GOOGLE_REALTIME_BROWSER_NEW_SESSION_TTL_MS = 60 * 1000;

53+

const MULAW_LINEAR_SAMPLES = new Int16Array(256);

54+55+

for (let i = 0; i < MULAW_LINEAR_SAMPLES.length; i += 1) {

56+

MULAW_LINEAR_SAMPLES[i] = decodeMulawSample(i);

57+

}

53585459

type GoogleRealtimeSensitivity = "low" | "high";

5560

type GoogleRealtimeThinkingLevel = "minimal" | "low" | "medium" | "high";

@@ -330,6 +335,8 @@ function buildFunctionDeclarations(tools: RealtimeVoiceTool[] | undefined): Func

330335331336

function buildGoogleLiveConnectConfig(config: GoogleRealtimeLiveConfig): LiveConnectConfig {

332337

const functionDeclarations = buildFunctionDeclarations(config.tools);

338+

const realtimeInputConfig = buildRealtimeInputConfig(config);

339+

const thinkingConfig = buildThinkingConfig(config);

333340

return {

334341

responseModalities: ["AUDIO" as Modality],

335342

...(typeof config.temperature === "number" && config.temperature > 0

@@ -344,15 +351,13 @@ function buildGoogleLiveConnectConfig(config: GoogleRealtimeLiveConfig): LiveCon

344351

},

345352

systemInstruction: config.instructions,

346353

...(functionDeclarations.length > 0 ? { tools: [{ functionDeclarations }] } : {}),

347-

...(buildRealtimeInputConfig(config)

348-

? { realtimeInputConfig: buildRealtimeInputConfig(config) }

349-

: {}),

354+

...(realtimeInputConfig ? { realtimeInputConfig } : {}),

350355

inputAudioTranscription: {},

351356

outputAudioTranscription: {},

352357

...(typeof config.enableAffectiveDialog === "boolean"

353358

? { enableAffectiveDialog: config.enableAffectiveDialog }

354359

: {}),

355-

...(buildThinkingConfig(config) ? { thinkingConfig: buildThinkingConfig(config) } : {}),

360+

...(thinkingConfig ? { thinkingConfig } : {}),

356361

};

357362

}

358363

@@ -487,12 +492,7 @@ class GoogleRealtimeVoiceBridge implements RealtimeVoiceBridge {

487492

this.audioStreamEnded = false;

488493

}

489494490-

const pcm = this.toInputPcm(audio);

491-

const pcm16k = resamplePcm(

492-

pcm,

493-

this.audioFormat.sampleRateHz,

494-

GOOGLE_REALTIME_INPUT_SAMPLE_RATE,

495-

);

495+

const pcm16k = this.toGoogleInputPcm16k(audio);

496496

this.session.sendRealtimeInput({

497497

audio: {

498498

data: pcm16k.toString("base64"),

@@ -617,6 +617,21 @@ class GoogleRealtimeVoiceBridge implements RealtimeVoiceBridge {

617617

return this.audioFormat.encoding === "pcm16" ? audio : mulawToPcm(audio);

618618

}

619619620+

private toGoogleInputPcm16k(audio: Buffer): Buffer {

621+

if (

622+

this.audioFormat.encoding === "g711_ulaw" &&

623+

this.audioFormat.sampleRateHz === 8_000 &&

624+

GOOGLE_REALTIME_INPUT_SAMPLE_RATE === 16_000

625+

) {

626+

return convertMulaw8kToPcm16k(audio);

627+

}

628+

return resamplePcm(

629+

this.toInputPcm(audio),

630+

this.audioFormat.sampleRateHz,

631+

GOOGLE_REALTIME_INPUT_SAMPLE_RATE,

632+

);

633+

}

634+620635

private toOutputAudio(pcm: Buffer, sampleRate: number): Buffer {

621636

return this.audioFormat.encoding === "pcm16"

622637

? resamplePcm(pcm, sampleRate, this.audioFormat.sampleRateHz)

@@ -726,6 +741,30 @@ class GoogleRealtimeVoiceBridge implements RealtimeVoiceBridge {

726741

}

727742

}

728743744+

function convertMulaw8kToPcm16k(muLaw: Buffer): Buffer {

745+

if (muLaw.length === 0) {

746+

return Buffer.alloc(0);

747+

}

748+

const pcm = Buffer.alloc(muLaw.length * 4);

749+

for (let i = 0; i < muLaw.length; i += 1) {

750+

const current = MULAW_LINEAR_SAMPLES[muLaw[i] ?? 0] ?? 0;

751+

const next = MULAW_LINEAR_SAMPLES[muLaw[i + 1] ?? muLaw[i] ?? 0] ?? current;

752+

pcm.writeInt16LE(current, i * 4);

753+

pcm.writeInt16LE(Math.round((current + next) / 2), i * 4 + 2);

754+

}

755+

return pcm;

756+

}

757+758+

function decodeMulawSample(value: number): number {

759+

const muLaw = ~value & 0xff;

760+

const sign = muLaw & 0x80;

761+

const exponent = (muLaw >> 4) & 0x07;

762+

const mantissa = muLaw & 0x0f;

763+

let sample = ((mantissa << 3) + 132) << exponent;

764+

sample -= 132;

765+

return sign ? -sample : sample;

766+

}

767+729768

async function createGoogleRealtimeBrowserSession(

730769

req: RealtimeVoiceBrowserSessionCreateRequest,

731770

): Promise<RealtimeVoiceBrowserSession> {