From c063ef771b6cc9ec15d18bfb5ae8db392438df2e Mon Sep 17 00:00:00 2001 From: Rhevan Kruger Date: Sun, 29 Sep 2024 21:24:17 +0200 Subject: [PATCH] cleanup/generalFinalization: fixed first time video capturing not showing audio mood --- frontend/lib/components/confirm_pop_up.dart | 3 +-- frontend/lib/pages/camera.dart | 28 ++++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/frontend/lib/components/confirm_pop_up.dart b/frontend/lib/components/confirm_pop_up.dart index 871b8f8..8d0c480 100644 --- a/frontend/lib/components/confirm_pop_up.dart +++ b/frontend/lib/components/confirm_pop_up.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import '../auth/auth_service.dart'; - class ConfirmationPopUp extends StatefulWidget { final String? imagePath; final String? transcribedText; @@ -136,7 +135,7 @@ class _ConfirmationPopUpState extends State { child: Padding( padding: const EdgeInsets.all(20.0), child: Text( - widget.transcribedText != null && widget.transcribedText!.isNotEmpty && widget.transcribedText.toString().toUpperCase() != 'YOU' && widget.transcribedText.toString().toUpperCase() != '..' + widget.transcribedText != null && widget.transcribedText!.isNotEmpty && widget.transcribedText.toString().toUpperCase() != 'YOU' && widget.transcribedText.toString().toUpperCase() != '. .' ? widget.transcribedText! : 'No transcription available', style: TextStyle( diff --git a/frontend/lib/pages/camera.dart b/frontend/lib/pages/camera.dart index dc0b84f..d76f319 100644 --- a/frontend/lib/pages/camera.dart +++ b/frontend/lib/pages/camera.dart @@ -34,6 +34,7 @@ class _CameraPageState extends State { AudioRecorder audioRecorder = AudioRecorder(); String audioMoodWeight = ''; bool audioReady = false; + int photoCount = 0; final List modes = ["Photo", "Video", "Audio"]; @@ -92,7 +93,7 @@ class _CameraPageState extends State { void _handleButtonPress() async { if (mode == "Video") { - setState(() { + setState(() async { innerCircleSize = innerCircleSize == 50.0 ? 60.0 : 50.0; innerCircleColor = innerCircleSize == 50.0 ? Colors.red : Colors.white; _audioRecord(true); @@ -120,7 +121,7 @@ class _CameraPageState extends State { innerCircleSize = 60.0; }); } else if (mode == "Audio") { - _audioRecord(false); + _audioRecord(false); } } @@ -160,7 +161,10 @@ class _CameraPageState extends State { isRecording = false; // Stop recording captureTimer?.cancel(); // Stop the timer print("Recording stopped. Moods: $returnedMoods"); - returnedMoods.add(audioMoodWeight); + if(audioMoodWeight != ''){ + returnedMoods.add(audioMoodWeight); + } + print("Recording stopped. Moods: $returnedMoods"); audioMoodWeight = ''; // Check if a picture has been taken @@ -168,7 +172,7 @@ class _CameraPageState extends State { await _takeForcedPicture(); // Take a picture if none exists } else { int count = 0; - while (!audioReady && count < 100) { + while (!audioReady && count < 10000000000) { await Future.delayed(Duration(milliseconds: 100)); // Check every 100ms count += 1; } @@ -191,8 +195,10 @@ class _CameraPageState extends State { // Send photo to method channel and get the mood String? mood = await _neuralNetMethodChannel.get_mood(pictureFile); setState(() { - returnedMoods.add(mood ?? 'Unknown'); // Store the mood - imagePaths.add(pictureFile.path); // Store the image path + if(mood != "") { + returnedMoods.add(mood); // Store the mood + imagePaths.add(pictureFile.path); // Store the image path + } }); print("Captured mood: $mood"); } @@ -276,8 +282,12 @@ class _CameraPageState extends State { print("RETURNED MOODS"); print(returnedMoods.toString()); + if(returnedMoods.length == imagePaths.length) { + returnedMoods.add(audioMoodWeight); + } + // Delay to give visual feedback - await Future.delayed(Duration(milliseconds: 200)); + await Future.delayed(Duration(milliseconds: 100)); // Send all the captured images during real-time video as a list Navigator.push( @@ -488,8 +498,8 @@ class _CameraPageState extends State { drawer: Drawer( shape: RoundedRectangleBorder( borderRadius: BorderRadius.only( - topRight: Radius.circular(50), // Adjust the radius as needed - bottomRight: Radius.circular(50), // Adjust the radius as needed + topRight: Radius.circular(50), // Adjust the radius as needed + bottomRight: Radius.circular(50), // Adjust the radius as needed ), ), backgroundColor: Theme.of(context).colorScheme.primary,