diff --git a/lib/screens/mapflow_shell.dart b/lib/screens/mapflow_shell.dart index d835e1f..2c542c1 100644 --- a/lib/screens/mapflow_shell.dart +++ b/lib/screens/mapflow_shell.dart @@ -727,12 +727,14 @@ class _AddExperienceFlowState extends ConsumerState { Future>? _nearbyPlacesFuture; StreamSubscription? _amplitudeSub; + Timer? _progressTimer; XFile? _recordedFile; var _step = 0; var _informationUnits = 0.0; var _recording = false; var _submitting = false; var _micAllowed = true; + var _heardVoice = false; var _noiseDb = -72.0; var _voicePeakDb = -34.0; var _liveLevel = 0.0; @@ -746,6 +748,7 @@ class _AddExperienceFlowState extends ConsumerState { @override void dispose() { _amplitudeSub?.cancel(); + _progressTimer?.cancel(); _audioRecorder.dispose(); super.dispose(); } @@ -783,10 +786,16 @@ class _AddExperienceFlowState extends ConsumerState { _amplitudeSub = _audioRecorder .onAmplitudeChanged(_amplitudeInterval) .listen(_handleAmplitude); + _progressTimer?.cancel(); + _progressTimer = Timer.periodic( + _amplitudeInterval, + (_) => _tickRecordingProgress(), + ); setState(() { _micAllowed = true; _recording = true; + _heardVoice = false; _liveLevel = 0; _informationUnits = 0; }); @@ -795,6 +804,8 @@ class _AddExperienceFlowState extends ConsumerState { Future _stopRecording() async { await _amplitudeSub?.cancel(); _amplitudeSub = null; + _progressTimer?.cancel(); + _progressTimer = null; final path = await _audioRecorder.stop(); _recordStopwatch.stop(); if (path != null && path.isNotEmpty) { @@ -812,12 +823,26 @@ class _AddExperienceFlowState extends ConsumerState { void _handleAmplitude(record.Amplitude amplitude) { final currentDb = amplitude.current; - final now = DateTime.now(); final level = _normalizeDbLevel(currentDb); - final informationDelta = _consumeInformationDelta(level, now); setState(() { _liveLevel = _smoothLevel(_liveLevel, level); + _heardVoice = _heardVoice || level > 0.08; + }); + } + + void _tickRecordingProgress() { + if (!_recording) { + return; + } + + final effectiveLevel = _heardVoice ? math.max(_liveLevel, 0.34) : _liveLevel; + final informationDelta = _consumeInformationDelta( + effectiveLevel, + DateTime.now(), + ); + + setState(() { _informationUnits = math.min( _minimumInformationUnits, _informationUnits + informationDelta,