-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from COS301-SE-2024/NonFuncTesting
Audio Integration
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'neural_net_service.dart'; // Import the service | ||
|
||
class ImageProcessingPage extends StatelessWidget { | ||
const ImageProcessingPage({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Image Processing Page'), | ||
), | ||
body: Center( | ||
child: ElevatedButton( | ||
onPressed: () async { | ||
NeuralNetService neuralNetService = NeuralNetService(); | ||
double avgResponseTime = await neuralNetService.processImagesAndGetAverageResponseTime(); | ||
_showAverageResponseTime(context, avgResponseTime); | ||
}, | ||
child: const Text('Select Images and Get Avg Response Time'), | ||
), | ||
), | ||
); | ||
} | ||
|
||
// Function to show average response time in a dialog | ||
void _showAverageResponseTime(BuildContext context, double avgResponseTime) { | ||
showDialog( | ||
context: context, | ||
builder: (BuildContext context) { | ||
return AlertDialog( | ||
title: const Text('Average Response Time'), | ||
content: Text('Average Response Time: $avgResponseTime ms'), | ||
actions: <Widget>[ | ||
TextButton( | ||
child: const Text('OK'), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:flutter/services.dart'; | ||
import 'package:file_picker/file_picker.dart'; | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
class NeuralNetService { | ||
static const MethodChannel _channel = MethodChannel('neural_net_method_channel'); | ||
|
||
|
||
Future<double> processImagesAndGetAverageResponseTime() async { | ||
List<File> selectedFiles = []; | ||
int totalResponseTime = 0; | ||
try { | ||
FilePickerResult? result = await FilePicker.platform.pickFiles( | ||
type: FileType.image, | ||
allowMultiple: true, | ||
); | ||
if (result != null) { | ||
selectedFiles = result.paths | ||
.where((path) => path != null) | ||
.map((path) => File(path!)) | ||
.toList() | ||
.take(10) | ||
.toList(); | ||
} else { | ||
print('No files selected'); | ||
return 0.0; | ||
} | ||
} on PlatformException catch (e) { | ||
print('Error: ${e.message}'); | ||
return 0.0; | ||
} | ||
|
||
// Step 2: Calculate the average response time | ||
for (var file in selectedFiles) { | ||
final stopwatch = Stopwatch()..start(); | ||
|
||
try { | ||
final imageBytes = await file.readAsBytes(); | ||
await _channel.invokeMethod('get_mood', {'image': imageBytes}); | ||
} on PlatformException catch (e) { | ||
print('Error: ${e.message}'); | ||
continue; | ||
} | ||
|
||
stopwatch.stop(); | ||
totalResponseTime += stopwatch.elapsedMilliseconds; | ||
} | ||
|
||
return selectedFiles.isNotEmpty ? totalResponseTime / selectedFiles.length : 0.0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters