Local Dictation Worker Client (local/worker-client.js)

openchamber · packages/web/server/lib/dictation/local/worker-client.js · javascript · MIT
voice, infra, tag:dictation, tag:onnx, tag:ipc, tag:sherpa

Lazily forks a local ONNX speech worker, correlates IPC by request id, and routes dictation session events. Reuse it for on-device transcription that unloads after idle.

// Source: https://github.com/openchamber/openchamber | License: MIT | Copyright 2025 Bohdan Triapitsyn
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Client for the dictation local-speech worker process.
 *
 * Lazily forks the worker on first use, correlates request/response messages
 * by requestId, routes session events to per-session EventEmitters, and
 * shuts the worker down after an idle TTL so the ONNX runtime does not sit
 * in memory while dictation is unused.
 */

import { fork } from 'child_process';
import { randomUUID } from 'crypto';
import { EventEmitter } from 'events';
import { fileURLToPath } from 'url';

import { applySherpaLoaderEnv } from './sherpa-loader.js';

// Every request is answered by the worker on its next event-loop turn, so this
// 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key