@@ -13,15 +13,20 @@ import { MicrophoneIcon } from '@phosphor-icons/react/dist/ssr';
1313import { useSession } from '@/components/app/session-provider' ;
1414import { AgentControlBar } from '@/components/livekit/agent-control-bar/agent-control-bar' ;
1515import { TrackControl } from '@/components/livekit/agent-control-bar/track-control' ;
16- import { TrackDeviceSelect } from '@/components/livekit/agent-control-bar/track-device-select' ;
17- import { TrackToggle } from '@/components/livekit/agent-control-bar/track-toggle' ;
16+ // import { TrackDeviceSelect } from '@/components/livekit/agent-control-bar/track-device-select';
17+ // import { TrackToggle } from '@/components/livekit/agent-control-bar/track-toggle';
1818import { Alert , AlertDescription , AlertTitle , alertVariants } from '@/components/livekit/alert' ;
1919import { AlertToast } from '@/components/livekit/alert-toast' ;
2020import { BarVisualizer } from '@/components/livekit/audio-visualizer/audio-bar-visualizer/_bar-visualizer' ;
2121import {
2222 AudioBarVisualizer ,
2323 audioBarVisualizerVariants ,
2424} from '@/components/livekit/audio-visualizer/audio-bar-visualizer/audio-bar-visualizer' ;
25+ import {
26+ AudioGridVisualizer ,
27+ type GridOptions ,
28+ } from '@/components/livekit/audio-visualizer/audio-grid-visualizer/audio-grid-visualizer' ;
29+ import { gridVariants } from '@/components/livekit/audio-visualizer/audio-grid-visualizer/demos' ;
2530import { Button , buttonVariants } from '@/components/livekit/button' ;
2631import { ChatEntry } from '@/components/livekit/chat-entry' ;
2732import {
@@ -191,8 +196,8 @@ export const COMPONENTS = {
191196 </ Container >
192197 ) ,
193198
194- // Audio visualizer
195- AudioVisualizer : ( ) => {
199+ // Audio bar visualizer
200+ AudioBarVisualizer : ( ) => {
196201 const barCounts = [ '0' , '3' , '5' , '7' , '9' ] ;
197202 const sizes = [ 'icon' , 'xs' , 'sm' , 'md' , 'lg' , 'xl' ] ;
198203 const states = [
@@ -309,6 +314,90 @@ export const COMPONENTS = {
309314 ) ;
310315 } ,
311316
317+ // Audio grid visualizer
318+ AudioGridVisualizer : ( ) => {
319+ const barCounts = [ '0' , '3' , '5' , '7' , '9' ] ;
320+ const states = [
321+ 'disconnected' ,
322+ 'connecting' ,
323+ 'initializing' ,
324+ 'listening' ,
325+ 'thinking' ,
326+ 'speaking' ,
327+ ] as AgentState [ ] ;
328+
329+ const { microphoneTrack, localParticipant } = useLocalParticipant ( ) ;
330+ const [ barCount , setBarCount ] = useState < string > ( barCounts [ 0 ] ) ;
331+ const [ state , setState ] = useState < AgentState > ( states [ 0 ] ) ;
332+
333+ const micTrackRef = useMemo < TrackReferenceOrPlaceholder | undefined > ( ( ) => {
334+ return state === 'speaking'
335+ ? ( {
336+ participant : localParticipant ,
337+ source : Track . Source . Microphone ,
338+ publication : microphoneTrack ,
339+ } as TrackReference )
340+ : undefined ;
341+ } , [ state , localParticipant , microphoneTrack ] ) ;
342+
343+ useMicrophone ( ) ;
344+
345+ return (
346+ < Container componentName = "AudioVisualizer" >
347+ < div className = "flex items-center gap-2" >
348+ < div className = "flex-1" >
349+ < label className = "font-mono text-xs uppercase" htmlFor = "state" >
350+ State
351+ </ label >
352+ < Select value = { state } onValueChange = { ( value ) => setState ( value as AgentState ) } >
353+ < SelectTrigger id = "state" className = "w-full" >
354+ < SelectValue placeholder = "Select a state" />
355+ </ SelectTrigger >
356+ < SelectContent >
357+ { states . map ( ( state ) => (
358+ < SelectItem key = { state } value = { state } >
359+ { state }
360+ </ SelectItem >
361+ ) ) }
362+ </ SelectContent >
363+ </ Select >
364+ </ div >
365+
366+ < div className = "flex-1" >
367+ < label className = "font-mono text-xs uppercase" htmlFor = "barCount" >
368+ Bar count
369+ </ label >
370+ < Select value = { barCount . toString ( ) } onValueChange = { ( value ) => setBarCount ( value ) } >
371+ < SelectTrigger id = "barCount" className = "w-full" >
372+ < SelectValue placeholder = "Select a bar count" />
373+ </ SelectTrigger >
374+ < SelectContent >
375+ { barCounts . map ( ( barCount ) => (
376+ < SelectItem key = { barCount } value = { barCount . toString ( ) } >
377+ { parseInt ( barCount ) || 'Default' }
378+ </ SelectItem >
379+ ) ) }
380+ </ SelectContent >
381+ </ Select >
382+ </ div >
383+ </ div >
384+
385+ < div className = "relative flex flex-col justify-center gap-4" >
386+ { gridVariants . map ( ( variant : GridOptions , idx ) => (
387+ < div key = { idx } className = "border-border grid place-items-center rounded-xl border p-8" >
388+ < AudioGridVisualizer
389+ state = { state }
390+ audioTrack = { micTrackRef ! }
391+ columnCount = { parseInt ( barCount ) || 5 }
392+ options = { variant }
393+ />
394+ </ div >
395+ ) ) }
396+ </ div >
397+ </ Container >
398+ ) ;
399+ } ,
400+
312401 // Agent control bar
313402 AgentControlBar : ( ) => {
314403 useMicrophone ( ) ;
0 commit comments