feat: mvp viode
This commit is contained in:
@@ -2,14 +2,17 @@ import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import '../../core/core.dart';
|
||||
import 'voice_session_controller.dart';
|
||||
|
||||
class VoiceModeOverlay extends StatefulWidget {
|
||||
final CharacterModel character;
|
||||
final VoiceSessionController controller;
|
||||
final VoidCallback onClose;
|
||||
|
||||
const VoiceModeOverlay({
|
||||
super.key,
|
||||
required this.character,
|
||||
required this.controller,
|
||||
required this.onClose,
|
||||
});
|
||||
|
||||
@@ -18,8 +21,6 @@ class VoiceModeOverlay extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _VoiceModeOverlayState extends State<VoiceModeOverlay> with SingleTickerProviderStateMixin {
|
||||
bool _isMicMuted = false;
|
||||
bool _isSpeakerOn = true;
|
||||
late AnimationController _controller;
|
||||
|
||||
String get _avatarUrl => CharacterRepository.getAvatarUrl(widget.character.avatarPath);
|
||||
@@ -30,10 +31,18 @@ class _VoiceModeOverlayState extends State<VoiceModeOverlay> with SingleTickerPr
|
||||
_controller = AnimationController(
|
||||
vsync: this, duration: const Duration(seconds: 2))
|
||||
..repeat(reverse: true);
|
||||
|
||||
// Listen to controller changes to update UI
|
||||
widget.controller.addListener(_onStateChange);
|
||||
}
|
||||
|
||||
void _onStateChange() {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.controller.removeListener(_onStateChange);
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -102,13 +111,14 @@ class _VoiceModeOverlayState extends State<VoiceModeOverlay> with SingleTickerPr
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_isMicMuted ? 'Mic Muted' : 'Listening...',
|
||||
_getStatusText(),
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(0.6),
|
||||
fontSize: 12,
|
||||
letterSpacing: 2,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -122,13 +132,23 @@ class _VoiceModeOverlayState extends State<VoiceModeOverlay> with SingleTickerPr
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
if (!_isMicMuted)
|
||||
// Show animation only when listening or speaking
|
||||
if (widget.controller.state == VoiceState.listening || widget.controller.state == VoiceState.speaking)
|
||||
AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, child) {
|
||||
double scale = 1.0;
|
||||
if (widget.controller.state == VoiceState.speaking) {
|
||||
// Faster pulse when AI is speaking
|
||||
scale = 0.8 + 0.3 * _controller.value;
|
||||
} else {
|
||||
// Slower pulse when listening
|
||||
scale = 0.8 + 0.1 * _controller.value;
|
||||
}
|
||||
|
||||
return Container(
|
||||
width: 200 * (0.8 + 0.2 * _controller.value),
|
||||
height: 200 * (0.8 + 0.2 * _controller.value),
|
||||
width: 200 * scale,
|
||||
height: 200 * scale,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
@@ -178,11 +198,13 @@ class _VoiceModeOverlayState extends State<VoiceModeOverlay> with SingleTickerPr
|
||||
builder: (context, child) {
|
||||
return Container(
|
||||
width: 4,
|
||||
height: _isMicMuted
|
||||
? 4
|
||||
: 10 + (20 * (index % 2 == 0 ? _controller.value : 1 - _controller.value)),
|
||||
height: widget.controller.state == VoiceState.speaking
|
||||
? 10 + (30 * (index % 2 == 0 ? _controller.value : 1 - _controller.value)) // Active wave
|
||||
: widget.controller.state == VoiceState.processing
|
||||
? 8 + (5 * (index % 2 == 0 ? _controller.value : 1 - _controller.value)) // Thinking wave
|
||||
: 4, // Idle
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(_isMicMuted ? 0.2 : 0.8),
|
||||
color: Colors.white.withOpacity(widget.controller.state != VoiceState.listening ? 0.8 : 0.4),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
);
|
||||
@@ -203,14 +225,14 @@ class _VoiceModeOverlayState extends State<VoiceModeOverlay> with SingleTickerPr
|
||||
children: [
|
||||
// Mic Toggle
|
||||
IconButton(
|
||||
onPressed: () => setState(() => _isMicMuted = !_isMicMuted),
|
||||
icon: Icon(_isMicMuted ? LucideIcons.micOff : LucideIcons.mic),
|
||||
onPressed: widget.controller.toggleMic,
|
||||
icon: Icon(widget.controller.isMicMuted ? LucideIcons.micOff : LucideIcons.mic),
|
||||
iconSize: 24,
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: _isMicMuted
|
||||
backgroundColor: widget.controller.isMicMuted
|
||||
? Colors.white
|
||||
: Colors.white.withOpacity(0.1),
|
||||
foregroundColor: _isMicMuted
|
||||
foregroundColor: widget.controller.isMicMuted
|
||||
? const Color(0xFF2E1065)
|
||||
: Colors.white,
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -231,20 +253,14 @@ class _VoiceModeOverlayState extends State<VoiceModeOverlay> with SingleTickerPr
|
||||
),
|
||||
),
|
||||
|
||||
// Speaker Toggle
|
||||
// Speaker Toggle - Placeholder for now
|
||||
IconButton(
|
||||
onPressed: () => setState(() => _isSpeakerOn = !_isSpeakerOn),
|
||||
icon: Icon(
|
||||
_isSpeakerOn ? LucideIcons.volume2 : LucideIcons.volumeX
|
||||
),
|
||||
onPressed: () {}, // TODO: Implement speaker toggle in controller
|
||||
icon: const Icon(LucideIcons.volume2),
|
||||
iconSize: 24,
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: _isSpeakerOn
|
||||
? Colors.white.withOpacity(0.1)
|
||||
: Colors.white.withOpacity(0.05),
|
||||
foregroundColor: _isSpeakerOn
|
||||
? Colors.white
|
||||
: Colors.white.withOpacity(0.5),
|
||||
backgroundColor: Colors.white.withOpacity(0.1),
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.all(16),
|
||||
minimumSize: const Size(64, 64),
|
||||
),
|
||||
@@ -261,4 +277,25 @@ class _VoiceModeOverlayState extends State<VoiceModeOverlay> with SingleTickerPr
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _getStatusText() {
|
||||
if (widget.controller.isMicMuted) return 'Microphone Muted';
|
||||
|
||||
switch (widget.controller.state) {
|
||||
case VoiceState.listening:
|
||||
if (widget.controller.recognizedText.isNotEmpty) {
|
||||
// Show last few words of what user said
|
||||
String text = widget.controller.recognizedText;
|
||||
if (text.length > 20) text = '...${text.substring(text.length - 20)}';
|
||||
return text;
|
||||
}
|
||||
return 'Listening...';
|
||||
case VoiceState.processing:
|
||||
return 'Thinking...';
|
||||
case VoiceState.speaking:
|
||||
return 'Speaking...';
|
||||
case VoiceState.error:
|
||||
return 'Error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user