passnger/5/3/4
This commit is contained in:
@@ -1,119 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:SEFER/controller/home/map_passenger_controller.dart';
|
||||
// import 'package:flutter_sound/flutter_sound.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:record/record.dart';
|
||||
|
||||
class AudioRecorderController extends GetxController {
|
||||
AudioPlayer audioPlayer = AudioPlayer();
|
||||
AudioRecorder recorder = AudioRecorder();
|
||||
|
||||
bool isRecording = false;
|
||||
String filePath = '';
|
||||
String? selectedFilePath;
|
||||
double currentPosition = 0;
|
||||
double totalDuration = 0;
|
||||
String? selectedFile;
|
||||
|
||||
Future<void> startRecording() async {
|
||||
final bool isPermissionGranted = await recorder.hasPermission();
|
||||
if (!isPermissionGranted) {
|
||||
// RecordingPermissionException('l');
|
||||
print('sss');
|
||||
return;
|
||||
}
|
||||
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
// Generate a unique file name using the current timestamp
|
||||
String fileName =
|
||||
'${DateTime.now().year}-${DateTime.now().month}-${DateTime.now().day}_${Get.find<MapPassengerController>().rideId}.m4a';
|
||||
filePath = '${directory.path}/$fileName';
|
||||
|
||||
// Define the configuration for the recording
|
||||
const config = RecordConfig(
|
||||
// Specify the format, encoder, sample rate, etc., as needed
|
||||
encoder: AudioEncoder.aacLc, // For example, using AAC codec
|
||||
sampleRate: 44100, // Sample rate
|
||||
bitRate: 128000, // Bit rate
|
||||
);
|
||||
|
||||
// Start recording to file with the specified configuration
|
||||
await recorder.start(config, path: filePath);
|
||||
|
||||
isRecording = true;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> stopRecording() async {
|
||||
final path = await recorder.stop();
|
||||
print(path);
|
||||
isRecording = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> playRecording() async {
|
||||
if (filePath != null) {
|
||||
await audioPlayer.setFilePath(filePath!);
|
||||
totalDuration = audioPlayer.duration?.inSeconds.toDouble() ?? 0;
|
||||
audioPlayer.play();
|
||||
|
||||
audioPlayer.positionStream.listen((position) {
|
||||
currentPosition = position.inSeconds.toDouble();
|
||||
});
|
||||
selectedFilePath = filePath;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<String>> getRecordedFiles() async {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
final files = await directory.list().toList();
|
||||
return files
|
||||
.map((file) => file.path)
|
||||
.where((path) => path.endsWith('.m4a'))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> playRecordedFile(String filePath) async {
|
||||
await audioPlayer.setFilePath(filePath);
|
||||
totalDuration = audioPlayer.duration?.inSeconds.toDouble() ?? 0;
|
||||
audioPlayer.play();
|
||||
|
||||
audioPlayer.positionStream.listen((position) {
|
||||
currentPosition = position.inSeconds.toDouble();
|
||||
});
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> deleteRecordedFile(String filePath) async {
|
||||
final file = File(filePath);
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
print('File deleted: $filePath');
|
||||
await getRecordedFiles();
|
||||
} else {
|
||||
print('File not found: $filePath');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteAllRecordedFiles() async {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
final files = await directory.list().toList();
|
||||
for (final file in files) {
|
||||
if (file.path.endsWith('.m4a')) {
|
||||
await deleteRecordedFile(file.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
audioPlayer.dispose();
|
||||
recorder.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:SEFER/constant/api_key.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/controller/home/map_passenger_controller.dart';
|
||||
import 'package:agora_rtc_engine/agora_rtc_engine.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
@@ -23,15 +22,10 @@ class CallController extends GetxController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
if (box.read(BoxName.passengerID) != null) {
|
||||
channelName = Get.find<MapPassengerController>().rideId; // 'sefer300'; //
|
||||
remoteUid = int.parse(Get.find<MapPassengerController>().driverPhone);
|
||||
uid = int.parse(box.read(BoxName.phone));
|
||||
} else {
|
||||
channelName = Get.find<MapDriverController>().rideId; // 'sefer300'; //
|
||||
remoteUid = int.parse(Get.find<MapDriverController>().passengerPhone);
|
||||
uid = int.parse(box.read(BoxName.phoneDriver));
|
||||
}
|
||||
|
||||
channelName = Get.find<MapDriverController>().rideId; // 'sefer300'; //
|
||||
remoteUid = int.parse(Get.find<MapDriverController>().passengerPhone);
|
||||
uid = int.parse(box.read(BoxName.phoneDriver));
|
||||
|
||||
initAgoraFull();
|
||||
}
|
||||
@@ -46,12 +40,8 @@ class CallController extends GetxController {
|
||||
// join();
|
||||
FirebaseMessagesController().sendNotificationToPassengerToken(
|
||||
'Call Income from Passenger',
|
||||
box.read(BoxName.passengerID) != null
|
||||
? '${'You have call from Passenger'.tr} ${box.read(BoxName.name)}'
|
||||
: '${'You have call from driver'.tr} ${box.read(BoxName.nameDriver)}',
|
||||
box.read(BoxName.passengerID) != null
|
||||
? Get.find<MapPassengerController>().driverToken
|
||||
: Get.find<MapDriverController>().tokenPassenger,
|
||||
'${'You have call from driver'.tr} ${box.read(BoxName.nameDriver)}',
|
||||
Get.find<MapDriverController>().tokenPassenger,
|
||||
[
|
||||
token,
|
||||
channelName,
|
||||
@@ -89,10 +79,9 @@ class CallController extends GetxController {
|
||||
},
|
||||
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
|
||||
// Get.snackbar("Remote user uid:$remoteUid joined the channel", '');
|
||||
status =
|
||||
'${box.read(BoxName.passengerID) != null ? Get.find<MapPassengerController>().driverName : Get.find<MapDriverController>().passengerName}'
|
||||
' joined'
|
||||
.tr;
|
||||
status = '${Get.find<MapDriverController>().passengerName}'
|
||||
' joined'
|
||||
.tr;
|
||||
remoteUid = remoteUid;
|
||||
update();
|
||||
},
|
||||
|
||||
@@ -106,7 +106,36 @@ class CRUD {
|
||||
Future.delayed(const Duration(seconds: 2));
|
||||
String extracted =
|
||||
await arabicTextExtractByVisionAndAI(imagePath: imagePath);
|
||||
await AI().geminiAiExtraction(prompt, extracted);
|
||||
|
||||
Map<String, dynamic> extractedData = extractText(extracted);
|
||||
print(extractedData);
|
||||
// await AI().geminiAiExtraction(prompt, extractedData);
|
||||
}
|
||||
|
||||
Map<String, dynamic> extractText(String jsonData) {
|
||||
Map<String, dynamic> data = jsonDecode(jsonData);
|
||||
List<List<String>> textLines = [];
|
||||
|
||||
for (var region in data['regions']) {
|
||||
List<String> lineTexts = [];
|
||||
for (var line in region['lines']) {
|
||||
String lineText = "";
|
||||
for (var word in line['words']) {
|
||||
lineText += word['text'] + " ";
|
||||
}
|
||||
lineText = lineText.trim();
|
||||
lineTexts.add(lineText);
|
||||
}
|
||||
textLines.add(lineTexts);
|
||||
}
|
||||
|
||||
// You can choose between returning a new JSON or a List based on your needs
|
||||
|
||||
// Option 1: Return a new JSON with "textLines" key
|
||||
return {"textLines": textLines};
|
||||
|
||||
// Option 2: Return a List of List<String> (lines with words)
|
||||
// return textLines;
|
||||
}
|
||||
|
||||
Future<dynamic> arabicTextExtractByVisionAndAI({
|
||||
@@ -122,7 +151,7 @@ class CRUD {
|
||||
String imagePathFull =
|
||||
'${AppLink.server}card_image/$imagePath-${box.read(BoxName.driverID) ?? box.read(BoxName.passengerID)}.jpg';
|
||||
|
||||
print('imagePath=$imagePathFull');
|
||||
// print('imagePath=$imagePathFull');
|
||||
var requestBody = {"url": imagePathFull};
|
||||
var response = await http.post(
|
||||
url,
|
||||
@@ -132,7 +161,7 @@ class CRUD {
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var responseBody = jsonDecode(response.body);
|
||||
// print(decode);
|
||||
print(responseBody);
|
||||
print('imagePath=$imagePathFull');
|
||||
return responseBody.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user