cd /news/artificial-intelligence/building-a-zero-upload-in-browser-ne… · home › topics › artificial-intelligence › article
[ARTICLE · art-177968] src=dev.to ↗ pub= topic=artificial-intelligence verified=true sentiment=↑ positive

Building a Zero-Upload In-Browser Neural Text-to-Speech Engine with Kokoro-82M, WebGPU & WebAssembly

UCDREAMS built a zero-upload, in-browser text-to-speech engine that runs the Kokoro-82M neural acoustic model locally via WebGPU with a multi-threaded WebAssembly SIMD fallback, synthesizing speech and exporting 16-bit PCM WAV files entirely in browser memory. The engine caches quantized ONNX weights in the browser Cache API to cut repeat initialization to roughly 300–600ms, splits text into sentence-level chunks synthesized in Web Workers for gapless playback, and writes the 44-byte RIFF/WAVE header client-side in under 5ms. The result is a zero-login voice generator that keeps confidential scripts off remote servers and avoids per-character API billing.

recommendation

Cache quantized ONNX weights in the browser Cache API and chunk text at sentence boundaries in Web Workers so first audio plays before full synthesis completes.

more in playbook: Inference and self-hosting
by read3 min views9 publishedNov 29, 2026

Cloud Text-to-Speech (TTS) APIs share two recurring bottlenecks: per-character billing that punishes long-form narration and forced server round-trips for scripts that may contain confidential product briefs, internal training notes, or unreleased scripts.

Modern browsers now expose WebGPU, WebAssembly SIMD, and Web Audio API primitives fast enough to run compact neural acoustic models (like Kokoro-82M and quantized VITS voices) completely inside browser RAM.

At UCDREAMS, we applied this architecture to build Free Text to Speech Online — a zero-login, zero-upload AI voice generator that synthesizes speech locally and exports lossless 16-bit PCM WAV audio straight from memory.

Not every visitor arrives on an M-series MacBook or discrete GPU desktop. A resilient browser TTS engine probes WebGPU adapter availability first and falls back transparently to multi-threaded WebAssembly (wasm-simd):

import * as ort from 'onnxruntime-web';

export async function createTtsInferenceSession(modelBytes: ArrayBuffer) {
  const hasWebGpu = typeof navigator !== 'undefined' && 'gpu' in navigator;
  let executionProviders: Array<'webgpu' | 'wasm'> = ['wasm'];

  if (hasWebGpu) {
    try {
      const adapter = await navigator.gpu.requestAdapter();
      if (adapter) {
        executionProviders = ['webgpu', 'wasm'];
      }
    } catch {
      executionProviders = ['wasm'];
    }
  }

  return ort.InferenceSession.create(modelBytes, {
    executionProviders,
    graphOptimizationLevel: 'all',
  });
}

Weights (80MB–160MB quantized) should never be re-downloaded across reloads. Storing fetched ONNX shards in the browser Cache API cuts repeat initialization down to cold-read disk speed (~300–600ms) while keeping backend egress at zero.

Running a 2,000-character script in one inference pass freezes perceived playback and spikes peak tensor allocations. Splitting text at punctuation boundaries with sentence-level normalization lets playback start as soon as the first sentence finishes synthesis:

export function splitIntoSpeakableChunks(input: string, maxChars = 220): string[] {
  const sentences = input
    .replace(/\s+/g, ' ')
    .trim()
    .split(/(?<=[.!?])\s+/);

  const chunks: string[] = [];
  let current = '';

  for (const sentence of sentences) {
    if ((current + ' ' + sentence).trim().length <= maxChars) {
      current = (current + ' ' + sentence).trim();
    } else {
      if (current) chunks.push(current);
      current = sentence;
    }
  }
  if (current) chunks.push(current);
  return chunks;
}

Each chunk synthesizes inside a dedicated Web Worker into a Float32Array PCM waveform (typically 24 kHz sample rate), which is queued sequentially onto an AudioContext timeline so sentences flow seamlessly without gaps or clicks.

Once all Float32Array chunks finish synthesizing, concatenating them and prepending a 44-byte RIFF/WAVE header takes less than 5ms in browser RAM — no server-side FFmpeg container needed:

export function encodeFloat32ToWavBlob(
  chunks: Float32Array[],
  sampleRate = 24000
): Blob {
  const totalSamples = chunks.reduce((acc, c) => acc + c.length, 0);
  const buffer = new ArrayBuffer(44 + totalSamples * 2);
  const view = new DataView(buffer);

  const writeAscii = (offset: number, str: string) => {
    for (let i = 0; i < str.length; i++) {
      view.setUint8(offset + i, str.charCodeAt(i));
    }
  };

  writeAscii(0, 'RIFF');
  view.setUint32(4, 36 + totalSamples * 2, true);
  writeAscii(8, 'WAVE');
  writeAscii(12, 'fmt ');
  view.setUint32(16, 16, true);           // PCM chunk size
  view.setUint16(20, 1, true);            // Linear PCM
  view.setUint16(22, 1, true);            // Mono
  view.setUint32(24, sampleRate, true);
  view.setUint32(28, sampleRate * 2, true);
  view.setUint16(32, 2, true);            // Block align
  view.setUint16(34, 16, true);           // Bits per sample
  writeAscii(36, 'data');
  view.setUint32(40, totalSamples * 2, true);

  let offset = 44;
  for (const chunk of chunks) {
    for (let i = 0; i < chunk.length; i++) {
      const clamped = Math.max(-1, Math.min(1, chunk[i]));
      view.setInt16(offset, clamped < 0 ? clamped * 0x8000 : clamped * 0x7fff, true);
      offset += 2;
    }
  }

  return new Blob([buffer], { type: 'audio/wav' });
}

Test neural WebGPU/WASM speech generation directly in your browser with zero sign-up or character limits:

Built by UCDREAMS Senior Engineers (UCDREAMS TECHNOLOGIES LLP). Whether you need an in-browser WebAssembly/WebGPU product, an edge RAG automation workflow, or a custom full-stack web platform:

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @ucdreams 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/building-a-zero-uplo…] indexed:0 read:3min 2026-11-29 · —