import { Mic, MicOff, Phone, PhoneOff, Loader2, MessageSquare } from 'lucide-react'; import { useVoiceChat } from '../hooks/useVoiceChat'; import SubtitleDisplay from './SubtitleDisplay'; export default function VoicePanel({ settings, onVoiceEnd, chatHistory = [], sessionId: parentSessionId }) { const { isActive, isMuted, isConnecting, subtitles, connectionState, error, duration, start, stop, toggleMute, clearError, } = useVoiceChat(); const formatTime = (s) => { const m = Math.floor(s / 60); const sec = s % 60; return `${m.toString().padStart(2, '0')}:${sec.toString().padStart(2, '0')}`; }; const handleStart = () => { start({ botName: settings.botName, systemRole: settings.systemRole, speakingStyle: settings.speakingStyle, modelVersion: settings.modelVersion, speaker: settings.speaker, enableWebSearch: settings.enableWebSearch, chatHistory: chatHistory.length > 0 ? chatHistory.slice(-10) : undefined, parentSessionId, }); }; return (
{/* Status Bar */}
{isActive ? `通话中 · ${formatTime(duration)}` : isConnecting ? '正在连接...' : '未连接'}
{isActive && (
模型: {settings.modelVersion} · {settings.botName}
)}
{/* Visualization Area */}
{/* Voice Wave Animation */}
{/* Outer rings */} {isActive && !isMuted && ( <>
)} {/* Center circle */}
{isConnecting ? ( ) : isActive ? ( isMuted ? ( ) : ( ) ) : ( )}
{/* AI Info */}

{settings.botName}

{isActive ? isMuted ? '麦克风已静音' : '正在聆听...' : '点击下方按钮开始语音通话'}

{/* Controls */}
{isActive ? ( <> ) : ( )}
{/* Error */} {error && (
{error}
)}
{/* Subtitles */}
); }