webdevpuneet.com

AI Voice Input Button — Free Mic Button with Live Transcript Snippet

AI Voice Input Button · Buttons · Plain HTML, CSS & JS · Live preview

CategoryButtons

Copy & paste

Source Code

<div class="vib-wrap">
  <div class="vib-transcript" id="vibTranscript">
    <span class="vib-placeholder" id="vibPlaceholder">Tap the mic and start speaking…</span>
  </div>

  <button type="button" class="vib-mic" id="vibMic" aria-label="Start voice input">
    <span class="vib-ring" id="vibRing1"></span>
    <span class="vib-ring" id="vibRing2"></span>
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="vib-icon">
      <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>
      <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>
      <line x1="12" y1="19" x2="12" y2="23"/>
      <line x1="8" y1="23" x2="16" y2="23"/>
    </svg>
  </button>

  <div class="vib-status" id="vibStatus">Tap to speak</div>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Real SpeechRecognition support
Uses the native browser API with interim results for live word-by-word transcription.
Graceful simulated fallback
Falls back automatically when the API is missing or permission is denied.
Sandbox-safe by design
Never shows a broken or dead state, even where mic access is blocked.
Pulsing listening animation
Staggered expanding rings signal active capture at a glance.
Live transcript panel
Text streams in as it's recognized, real or simulated.
Toggle start/stop
One button both starts and stops listening.
Accessible labeling
aria-label updates between "Start" and "Stop voice input".
No dependencies
Pure HTML, CSS, and vanilla JavaScript using only native browser APIs.

About this UI Snippet

AI Voice Input Button — Real Speech Recognition with a Simulated Fallback

Screenshot of the AI Voice Input Button snippet rendered live

Voice input is now a standard entry point into AI chat products — a round mic button that pulses while listening and streams a live transcript underneath. This snippet builds that button using the browser's native SpeechRecognition API where it's available, and falls back to a simulated typing effect everywhere else, so the demo always looks alive even inside a sandboxed preview iframe where microphone permission is typically blocked.

Real recognition first

When window.SpeechRecognition or window.webkitSpeechRecognition exists, clicking the mic starts a real recognition session with interimResults: true, streaming partial transcripts into the transcript panel as the browser recognizes speech, word by word, exactly like the voice input in a production AI chat product.

A fallback that never looks broken

Microphone access is one of the most commonly blocked permissions in embedded and sandboxed contexts. Rather than showing a dead button or a permission error, this snippet catches both the "API doesn't exist" case and the onerror case (permission denied, no device, blocked context) and drops into a simulated mode: the mic pulses exactly as it would while listening, and a realistic sentence types itself into the transcript panel character by character. A viewer previewing the sandbox sees a fully working interaction either way — the same fail-into-simulation pattern used elsewhere in this library for browser-permission-gated demos.

Pulsing rings, not just a color change

While listening, two .vib-ring elements animate outward from the button with a staggered delay, producing a sonar-like pulse that reads as "actively capturing audio" at a glance — far more legible than a static color swap, especially from across a UI where the button is small.

Where this fits in an AI product

Drop it beside an AI chat interface input as an alternate entry method, or pair it with an AI persona selector so voice queries route to the chosen assistant style. The transcript panel's structure also works well next to an AI streaming response to show the full round trip from spoken question to generated answer.

Customizing it

Swap SIM_TRANSCRIPT for a set of rotating example phrases, wire the final transcript to your chat input's submit handler, or add a confidence score readout using the results[i][0].confidence value the real API already provides.

Step by step

How to Use

  1. 1
    Paste HTML, CSS, and JSA round mic button renders with an empty transcript panel above it.
  2. 2
    Click the mic buttonIf your browser supports SpeechRecognition and grants permission, it listens for real speech.
  3. 3
    Speak or waitIn a sandboxed preview, permission is usually blocked — the button automatically falls back to a simulated transcript typing itself out.
  4. 4
    Watch the pulsing ringsTwo staggered rings animate outward while listening, real or simulated.
  5. 5
    Click again to stopStops real recognition or cancels the simulation early.
  6. 6
    Wire up the transcriptRead the final text from the transcript panel and submit it to your chat handler.

Real-world uses

Common Use Cases

AI chat input bars
Add voice entry next to an AI chat interface composer, with a live transcript streaming beneath a pulsing round mic.
Voice-first assistants
Pair with an AI persona selector so users can choose how the assistant responds to what they say.
Accessibility-focused products
Offer voice as an alternative to typing, using interim results from the browser's SpeechRecognition so text appears as people speak.
Search interfaces
Let users speak a search query, with a simulated fallback that keeps the button working when microphone access is unavailable.
Notes and sandbox demos
Capture short voice memos in meeting tools, or show a working voice interaction in a sandbox where permission is denied.
Related: Async Button with Real Progress Fill (Not a Fake Spinner)
See the Async Button with Real Progress Fill (Not a Fake Spinner) for a related buttons pattern worth pairing with this one.
Related: Dual-Hold Safety Button
See the Dual-Hold Safety Button for a related buttons pattern worth pairing with this one.

Got questions?

Frequently Asked Questions

The button catches both the missing-API case and the SpeechRecognition onerror event (which fires on permission denial) and automatically switches to a simulated mode: the same pulsing animation plays and a realistic transcript types itself out character by character, so the demo never looks broken.

Chrome, Edge, and Safari support it via the vendor-prefixed webkitSpeechRecognition (or the unprefixed SpeechRecognition in newer Chromium versions). Firefox does not support it as of this writing, so those visitors automatically see the simulated fallback.

In the real recognition path, the onresult handler concatenates every result's transcript into one string on each event — read that same value (or track it in a variable) when recognition.onend fires, and pass it to your submit function. In the simulated path, use the fully typed SIM_TRANSCRIPT string once the interval completes.

Yes — SIM_TRANSCRIPT is a single string. Replace it with any example query relevant to your product, or randomly pick from an array of a few example phrases each time the simulation runs so repeat demos vary.

Wrap the SpeechRecognition setup and the simulated fallback in a mount effect (or a composable/service in Vue/Angular), store the transcript and listening state as component state, and bind the mic button's click handler to your start/stop function. Clean up by stopping recognition and clearing the interval on unmount.