165

Live Waveform

PreviousNext

Real-time canvas-based audio waveform visualizer with microphone input and customizable rendering modes.

Live Audio Waveform

Real-time microphone input visualization with audio reactivity

<script setup lang="ts">
import { LiveWaveform } from '@/components/elevenlabs-ui/live-waveform'
import { Button } from '@/components/ui/button'
import { ref } from 'vue'

const active = ref(false)
const processing = ref(false)
const mode = ref<'static' | 'scrolling'>('static')

function handleToggleActive() {
  active.value = !active.value
  // If starting to listen, stop processing
  if (active.value) {
    processing.value = false
  }
}

function handleToggleProcessing() {
  processing.value = !processing.value
  // If starting processing, stop listening
  if (processing.value) {
    active.value = false
  }
}

function toggleMode() {
  mode.value = mode.value === 'static' ? 'scrolling' : 'static'
}
</script>

<template>
  <div class="bg-card w-full rounded-lg border p-6">
    <div class="mb-4">
      <h3 class="text-lg font-semibold">
        Live Audio Waveform
      </h3>
      <p class="text-muted-foreground text-sm">
        Real-time microphone input visualization with audio reactivity
      </p>
    </div>

    <div class="space-y-4">
      <LiveWaveform
        :active="active"
        :processing="processing"
        :height="80"
        :bar-width="3"
        :bar-gap="2"
        :mode="mode"
        :fade-edges="true"
        bar-color="gray"
        :history-size="120"
      />

      <div class="flex flex-wrap justify-center gap-2">
        <Button
          size="sm"
          :variant="active ? 'default' : 'outline'"
          @click="handleToggleActive"
        >
          {{ active ? "Stop" : "Start" }} Listening
        </Button>

        <Button
          size="sm"
          :variant="processing ? 'default' : 'outline'"
          @click="handleToggleProcessing"
        >
          {{ processing ? "Stop" : "Start" }} Processing
        </Button>

        <Button
          size="sm"
          variant="outline"
          @click="toggleMode"
        >
          Mode: {{ mode === "static" ? "Static" : "Scrolling" }}
        </Button>
      </div>
    </div>
  </div>
</template>

Installation

pnpm dlx elevenlabs-ui-vue@latest add live-waveform

Usage

import { LiveWaveform } from "@/components/elevenlabs-ui/live-waveform"
<LiveWaveform active="true" />

Examples

Static Mode

<LiveWaveform active="true" mode="static" />

Scrolling Mode

<LiveWaveform :active="true" :mode="scrolling" />

Processing State

Shows an animated wave pattern while waiting for input.

<LiveWaveform :processing="true" :mode="static" />

Custom Styling

<LiveWaveform
  :active="true"
  :barWidth="4"
  :barHeight="6"
  :barGap="2"
  :barColor="'#3b82f6'"
  :height="100"
  :fadeEdges="true"
/>

API Reference

LiveWaveform

A canvas-based real-time audio visualizer with microphone input support.

Props

PropTypeDefaultDescription
activebooleanfalseWhether to actively listen to microphone input
processingbooleanfalseShow processing animation when not active
barWidthnumber3Width of each bar in pixels
barHeightnumber4Height of each bar in pixels
barGapnumber1Gap between bars in pixels
barRadiusnumber1.5Border radius of bars
barColorstring-Color of the bars (defaults to text color)
fadeEdgesbooleantrueWhether to fade the edges of the waveform
fadeWidthnumber24Width of the fade effect in pixels
heightstring | number64Height of the waveform
sensitivitynumber1Audio sensitivity multiplier
smoothingTimeConstantnumber0.8Audio analyser smoothing (0-1)
fftSizenumber256FFT size for audio analysis
historySizenumber60Number of bars to keep in history (scrolling)
updateRatenumber30Update rate in milliseconds
mode"scrolling" | "static""static"Visualization mode
classstring-Custom CSS class
...propsHTMLAttributes-All standard div element props

Emits

EventTypeDescription
error(error: Error) => voidCallback when an error occurs
stream-ready(stream: MediaStream) => voidCallback when stream is ready
stream-end() => voidCallback when when stream ends

Notes

  • Uses Web Audio API for real-time frequency analysis
  • Automatically requests microphone permissions when active="true"
  • Canvas-based rendering with HiDPI support
  • Properly cleans up media streams and audio contexts on unmount
  • Static mode: Displays symmetric waveform bars across multiple frequency bands (detailed visualization)
  • Scrolling mode: Shows historical average audio volume as bars scrolling from right to left (timeline view)
  • Processing state: Shows animated waves while waiting for input
  • Smooth transitions between active, processing, and idle states
  • Scrolling mode builds up history gradually - bars appear from right and fill over time