import { useState, useRef } from 'react' import { startRecording, stopRecording, sendAudioToBackend, playAudioBlob } from '../services/audioService' export default function Home() { const [recording, setRecording] = useState(false) const [playing, setPlaying] = useState(false) const [isProcessing, setIsProcessing] = useState(false) const mediaRecorderRef = useRef(null) const audioChunksRef = useRef([]) const audioRef = useRef(null) async function handleStartRecording() { await startRecording(mediaRecorderRef, audioChunksRef, setRecording, handleSendAudio) } function handleStopRecording() { stopRecording(mediaRecorderRef, setRecording) } async function handleSendAudio(blob) { try { setIsProcessing(true) const audioBlob = await sendAudioToBackend(blob) playAudioBlob(audioBlob, audioRef, setPlaying) } catch (error) { // Show a more user-friendly error notification const errorDiv = document.createElement('div') errorDiv.className = 'fixed top-4 right-4 bg-red-500 text-white px-6 py-4 rounded-lg shadow-lg z-50 transform transition-all duration-300' errorDiv.textContent = `Error: ${error.message}` document.body.appendChild(errorDiv) setTimeout(() => { errorDiv.style.transform = 'translateX(100%)' setTimeout(() => document.body.removeChild(errorDiv), 300) }, 3000) } finally { setIsProcessing(false) } } return (
Experience the future of voice interaction. Press and hold to record your voice, or simply click to toggle recording mode.
Your AI assistant's response will play here
Press & Hold
Hold the button down while speaking
Or Click Toggle
Click once to start, click again to stop
Listen
Your AI assistant will respond with audio