Next.js 15 application with TypeScript for real-time AI voice conversations.
- Next.js 15.1.3 - React framework with App Router
- React 18.3.1 - UI library
- TypeScript 5.7.2 - Type safety
- Tailwind CSS 3.4.17 - Styling
- LiveKit Client 2.9.0 - WebRTC for audio streaming
npm installCreate .env.local:
NEXT_PUBLIC_BACKEND_URL=http://localhost:8000
npm run devnpm run build
npm startfrontend/
├── app/
│ ├── globals.css # Global styles
│ ├── icon.svg # Favicon
│ ├── layout.tsx # Root layout
│ └── page.tsx # Home page
├── components/
│ └── AIVoiceConversation.tsx # Main UI component
├── hooks/
│ └── useVoiceConversation.ts # Voice conversation logic
└── package.json
Main UI component that displays:
- Connection status indicator
- Microphone status
- User transcript (what you said)
- AI response text
- Error messages
- Connect/Disconnect buttons
Custom hook handling:
- LiveKit room connection
- Audio recording with Voice Activity Detection (VAD)
- Silence detection (2 seconds)
- API calls to backend (transcribe, respond)
- Audio playback of AI responses
- Continuously monitors audio levels
- Detects when user starts speaking
- Detects 2 seconds of silence
- Automatically sends audio to backend
- User speaks → Audio recorded continuously
- User stops (2s silence) → Recording stops
- Audio sent to backend → Transcribed
- Transcript displayed immediately
- AI generates response → Text + Audio returned
- AI response displayed and played
- Ready for next question
- Cannot send new audio while backend is processing
- Cannot send new audio while AI audio is playing
- Ensures sequential conversation flow
Monitors microphone input in real-time:
- Analyzes audio frequency levels
- Detects speech (average > 5)
- Triggers 2-second silence timer
- Stops recording when silence detected
Handles complete conversation cycle:
- Sends audio to
/transcribeendpoint - Displays transcribed text
- Sends text to
/respondendpoint - Displays AI response text
- Plays AI response audio
Sets up continuous audio recording:
- Creates MediaRecorder with WebM format
- Configures Web Audio API for analysis
- Starts Voice Activity Detection loop
- Restarts recording after each sentence
NEXT_PUBLIC_BACKEND_URL- Backend API URL (default: http://localhost:8000)
livekit-client- WebRTC client for audio streamingnext- React frameworkreact- UI librarytailwindcss- Utility-first CSS
- Modern browser with WebRTC support (Chrome, Firefox, Safari, Edge)
- Microphone access permission
- HTTPS (or localhost for development)