live-waveform
elevenlabs/live-waveformFreeComponent
shadcn/ui publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/elevenlabs/ui/main/apps/www/public/r/live-waveform.jsonSource
1"use client"23import { useEffect, useRef, type HTMLAttributes } from "react"45import { cn } from "@/lib/utils"67export type LiveWaveformProps = HTMLAttributes<HTMLDivElement> & {8 active?: boolean9 processing?: boolean10 deviceId?: string11 barWidth?: number12 barHeight?: number13 barGap?: number14 barRadius?: number15 barColor?: string16 fadeEdges?: boolean17 fadeWidth?: number18 height?: string | number19 sensitivity?: number20 smoothingTimeConstant?: number21 fftSize?: number22 historySize?: number23 updateRate?: number24 mode?: "scrolling" | "static"25 onError?: (error: Error) => void26 onStreamReady?: (stream: MediaStream) => void27 onStreamEnd?: () => void28}2930export const LiveWaveform = ({31 active = false,32 processing = false,33 deviceId,34 barWidth = 3,35 barGap = 1,36 barRadius = 1.5,37 barColor,38 fadeEdges = true,39 fadeWidth = 24,40 barHeight: baseBarHeight = 4,41 height = 64,42 sensitivity = 1,43 smoothingTimeConstant = 0.8,44 fftSize = 256,45 historySize = 60,46 updateRate = 30,47 mode = "static",48 onError,49 onStreamReady,50 onStreamEnd,51 className,52 ...props53}: LiveWaveformProps) => {54 const canvasRef = useRef<HTMLCanvasElement>(null)55 const containerRef = useRef<HTMLDivElement>(null)56 const historyRef = useRef<number[]>([])57 const analyserRef = useRef<AnalyserNode | null>(null)58 const audioContextRef = useRef<AudioContext | null>(null)59 const streamRef = useRef<MediaStream | null>(null)60 const animationRef = useRef<number>(0)61 const lastUpdateRef = useRef<number>(0)62 const processingAnimationRef = useRef<number | null>(null)63 const lastActiveDataRef = useRef<number[]>([])64 const transitionProgressRef = useRef(0)65 const staticBarsRef = useRef<number[]>([])66 const needsRedrawRef = useRef(true)67 const gradientCacheRef = useRef<CanvasGradient | null>(null)68 const lastWidthRef = useRef(0)6970 const heightStyle = typeof height === "number" ? `${height}px` : height7172 // Handle canvas resizing73 useEffect(() => {74 const canvas = canvasRef.current75 const container = containerRef.current76 if (!canvas || !container) return7778 const resizeObserver = new ResizeObserver(() => {79 const rect = container.getBoundingClientRect()80 const dpr = window.devicePixelRatio || 18182 canvas.width = rect.width * dpr83 canvas.height = rect.height * dpr84 canvas.style.width = `${rect.width}px`85 canvas.style.height = `${rect.height}px`8687 const ctx = canvas.getContext("2d")88 if (ctx) {89// … truncated
Files it writes
More from shadcn/ui
All 50 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| audio-playeraudio-player | shadcn/ui | Components | Free | 2 deps | |
| bar-visualizerbar-visualizer | shadcn/ui | Components | Free | no deps | |
| conversationconversation | shadcn/ui | Components | Free | 1 dep | |
| conversation-barconversation-bar | shadcn/ui | Components | Free | 1 dep | |
| matrixmatrix | shadcn/ui | Components | Free | no deps | |
| messagemessage | shadcn/ui | Components | Free | 1 dep | |
| mic-selectormic-selector | shadcn/ui | Components | Free | no deps | |
| orborb | shadcn/ui | Components | Free | 4 deps |
