Skip to content

Commit

Permalink
cleanup/generalFinalization: fixed first time video capturing not sho…
Browse files Browse the repository at this point in the history
…wing audio mood
  • Loading branch information
RhevanKruger committed Sep 29, 2024
1 parent 9b7912f commit c063ef7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
3 changes: 1 addition & 2 deletions frontend/lib/components/confirm_pop_up.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter/material.dart';

import '../auth/auth_service.dart';


class ConfirmationPopUp extends StatefulWidget {
final String? imagePath;
final String? transcribedText;
Expand Down Expand Up @@ -136,7 +135,7 @@ class _ConfirmationPopUpState extends State<ConfirmationPopUp> {
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(
Expand Down
28 changes: 19 additions & 9 deletions frontend/lib/pages/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class _CameraPageState extends State<CameraPage> {
AudioRecorder audioRecorder = AudioRecorder();
String audioMoodWeight = '';
bool audioReady = false;
int photoCount = 0;


final List<String> modes = ["Photo", "Video", "Audio"];
Expand Down Expand Up @@ -92,7 +93,7 @@ class _CameraPageState extends State<CameraPage> {

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);
Expand Down Expand Up @@ -120,7 +121,7 @@ class _CameraPageState extends State<CameraPage> {
innerCircleSize = 60.0;
});
} else if (mode == "Audio") {
_audioRecord(false);
_audioRecord(false);
}
}

Expand Down Expand Up @@ -160,15 +161,18 @@ class _CameraPageState extends State<CameraPage> {
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
if (imagePaths.isEmpty) {
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;
}
Expand All @@ -191,8 +195,10 @@ class _CameraPageState extends State<CameraPage> {
// 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");
}
Expand Down Expand Up @@ -276,8 +282,12 @@ class _CameraPageState extends State<CameraPage> {
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(
Expand Down Expand Up @@ -488,8 +498,8 @@ class _CameraPageState extends State<CameraPage> {
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,
Expand Down

0 comments on commit c063ef7

Please sign in to comment.