voiceloop is a zero-runtime-dependency JavaScript library designed to provide a smooth, interruptible voice agent experience in the browser, making voice conversations within web pages feel closer to a real-time assistant. It covers the complete voice loop: voice activity detection (VAD) → speech-to-text (STT) → large language model (LLM) → text-to-speech (TTS), and handles the harder parts within it.
Key capabilities
- True barge-in: interruption is triggered by transcribed new words, not microphone volume. Therefore, the agent's own voice does not falsely trigger an interruption. According to the material, with echo cancellation (AEC) disabled, self-interruption is 0 times, while Pipecat is 20/30 and OpenAI Realtime is 17/30 (benchmark data).
- Self-echo filtering: a word-level echo filter allows echo-coupled turns to still run at full speed, and the material says it is on par with clean turns (930ms).
- Low-latency first audio: TTS reads the first sentence while the LLM is writing the second sentence, and the LLM call can be speculatively started as soon as the user's turn ends in a pause. The material says the first segment of audio appears within 1 second.
- Turn serialization: rapid successive turns, tool results, holds, and replays do not overwrite each other, locked down by 184 tests.
- Local-first: Silero VAD and Piper TTS run as WASM within the browser tab, free of charge and without cloud round trips (loaded from CDN first, then cached).
- Click-to-jump: click anywhere in the transcript to jump the speech to that position, either forward or backward.
- Pluggable: can connect to any OpenAI-compatible LLM (or custom async generator), multiple STT options (browser Web Speech, ElevenLabs Scribe, Deepgram Flux, Speechmatics, etc.), and replaceable TTS.
How to use
- The online demo requires no key and no installation, and runs directly in a browser tab. The demo starts in echo mode: browser Web Speech for STT, local Piper for TTS, and a repeating "LLM" as a placeholder, so it is zero-cost and zero-backend. The material points out that this is not the best configuration, and the best configuration (Deepgram STT + ElevenLabs Flash TTS) can reduce latency from 2100ms to 900ms.
- Running locally: file:// does not work, and microphone and module imports require http://localhost or https. You can start reading from examples/simple-browser.html; the material says that is the same loop, with no UI, at about 100 lines.
- Cloud provider authentication: short-lived tokens are minted through the backend, and the raw API key never reaches the page. Two ways: sttTokenUrl (a POST route on the server that returns { token }), or getSttToken (an async callback (provider) => ({ token })). The material mentions that in examples/token-worker/ there is a complete single-file Cloudflare Worker example that provides rate limiting for Deepgram, ElevenLabs TTS, and an LLM proxy.
- Browser compatibility: browsers without SpeechRecognition (Firefox, WebKitGTK) will make webspeech fall back to elevenlabs, so a token route needs to be configured. On iOS, a cloud STT provider is recommended, because Safari has supported webkitSpeechRecognition since 14.5, but the implementation is not reliable enough: recognition often goes silent after the first utterance without firing onend or onerror, playing audio on the same page can also kill it in the same way, and iOS lowers speaker volume while the recognizer is using the microphone—and that is exactly what a talking agent needs. The material recommends using webspeech on desktop Chrome as the zero-key default, and on mobile pointing sttProvider to elevenlabs, deepgram, or speechmatics.
- Bring your own LLM: the default adapter uses OpenAI's streaming format (OpenAI, Groq, Cerebras, OpenRouter, Ollama, vLLM, LiteLLM, etc.); otherwise, an async generator can be passed in.
- Tool calling: the material says tools are executed while the agent is still speaking. The default adapter is a loop that feeds each result back to the model within the same reply, so the model continues speaking with the answer (at most 6 model messages per turn). Results are recorded natively (tool_use / tool_result), the model does not repeatedly trigger the same call, agent.notify('[TOOL RESULT get_weather] 22°C sunny') can return asynchronous results for subsequent voice output. Tools are fire-and-forget rather than wait-based: a turn completes when the agent stops speaking, and a slow or hanging tool does not block the conversation. Long-running work should be placed in a tool that returns quickly (e.g., "checking"), with the result delivered later via notify().
- Custom adapter flags: executesTools indicates that tool blocks carrying result or error are reported rather than executed again; acceptsToolGate is a necessary condition for keeping speculative prefetch enabled, the gate is a promise that resolves only when the turn commits, text can be speculatively streamed, tools wait at the gate, and discarded speculation rejects the gate.
- Constructor options and events: full types and item-by-item descriptions are in src/index.d.ts. Get events via onEvent(e): state, stt, assistant, tool, vad, level, echo, error, diag. tool events carry { name, id, args } as well as result (settled) or running: true (the adapter declares it is still executing), and should be rendered as the same chip by id.
- level event: { level } represents microphone loudness from 0..1, emitted roughly every 256ms during capture, based on a perceptual curve, derived from frames already present in the pipeline (no second microphone capture, no AnalyserNode), and can be used to drive a volume meter or a reactive orb; it should decay based on elapsed time. This event is not emitted for selfCapture providers (webspeech has its own microphone).
- Interruption has no dedicated "truncated" event: the final assistant event carries both the heard text and the written full, and a non-empty full.slice(text.length) indicates the reply was cut off before the remainder was spoken. It does not state the reason; voice barge-in, interrupt(), superseded turns, and setTtsMuted(true) all end the reply in the same way.
- Tuning: all latency and sensitivity knobs are in src/tuning.js, including VAD threshold, barge-in minimum character count, sentence-breaking aggressiveness, prefetch stability window, and echo matching threshold. Constructor options (bargeInMinChars, vadOptions, turnDetector, maxPauseMs) can be overridden per agent.
- Liveness: the turn loop is strictly serialized, tools are dispatched and never awaited (a suspended tool only loses its own result), an aborted LLM stream is detached rather than drained, maxPauseMs is a single wall-clock deadline limiting how long turnDetector keeps a turn open. Synthesis is the exception: a custom _synth() that never settles will block the reply that needs it.
- TTS: the default is Piper (local WASM, free, multilingual and multi-voice), with optional ElevenLabs (cloud, human-level voices, keys kept server-side behind a proxy route). Both behave the same (sentence streaming, bar-level barge-in, seek, speculative pre-synthesis), only the voice and cost differ: Piper is free and offline, ElevenLabs is paid and more human-like. Custom engines can extend StreamingTTS and implement a single method; sentence chunking, playback bars, click-to-seek, barge-in and progress reporting are all provided by the base class.
Latency notes
The material states that latency is measured rather than claimed. voice-agent-bench (developed in bench/ then split into a separate repository) is a black-box harness — audio in, audio out, zero integration — scoring voiceloop against competing stacks on the same scripted conversations and the same fixed mock LLM: reply latency (median speech-to-speech), and how often the system misbehaves (talking over a user's hesitation, or cutting off its own reply when its own voice echoes into the microphone, with no AEC). The material also mentions Soniox as a faster and cheaper STT ($0.12/hr vs $0.39/hr, 60+ languages), but its endpoint detection is more acoustic: it entered mid-sentence pauses in 15/30 hesitant turns, and continued speaking in 7 of those (Flux: 2 → 0). Choose Flux when "never interrupt" matters more than 100–400ms. Full tables are in bench/results/SONIOX-VS-DEEPGRAM.md and results/RESULTS.md.
Testing and licensing
The material states that the test suite locks down turn serialization, hold/release semantics, tool deduplication, self-echo classification, prefetch adoption rules, playback-bar seeking, and the turn-boundary state machine for every STT provider. voiceloop is a trademark of TODOforAI: the code may be freely used, modified and redistributed under the MIT license, but forks or derivative projects must not be presented as the official voiceloop project, nor published under the voiceloop name.