step 9 : proses rekaman dan upload rekaman ke BE
This commit is contained in:
@@ -9,16 +9,12 @@ abstract class BaseRepository {
|
||||
|
||||
// POST audio
|
||||
Future<Map<String, dynamic>> postAudio({
|
||||
required String filePath,
|
||||
// required String filePath,
|
||||
required FormData formData,
|
||||
required String service,
|
||||
String? token,
|
||||
}) async {
|
||||
try {
|
||||
FormData formData = FormData.fromMap({
|
||||
"audio":
|
||||
await MultipartFile.fromFile(filePath, filename: "rekaman.mp3"),
|
||||
});
|
||||
|
||||
final response = await dio.post(
|
||||
// Constant.baseUrl + service,
|
||||
service,
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../model/voice_to_text_model.dart';
|
||||
import 'base_repository.dart';
|
||||
|
||||
@@ -9,7 +13,8 @@ class VoiceToTextRepository extends BaseRepository {
|
||||
required String userId,
|
||||
}) async {
|
||||
// final service = "${Constant.baseUrl}xauth/login";
|
||||
final service = "http://${host}/one-api/scan-ktp/Voicetotext/listRiwayatRekaman";
|
||||
final service =
|
||||
"http://${host}/one-api/scan-ktp/Voicetotext/listRiwayatRekaman";
|
||||
final resp = await post(param: {"userId": userId}, service: service);
|
||||
|
||||
final result = List<VoiceToTextModel>.empty(growable: true);
|
||||
@@ -20,4 +25,37 @@ class VoiceToTextRepository extends BaseRepository {
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// proses upload
|
||||
Future<List<VoiceToTextModel>> prosesUpload({
|
||||
required String host,
|
||||
required String userId,
|
||||
required String filePath,
|
||||
required String qrCodeStr,
|
||||
}) async {
|
||||
// final service = "${Constant.baseUrl}xauth/login";
|
||||
final service = "http://${host}/one-api/scan-ktp/Voicetotext/uploadRekaman";
|
||||
|
||||
FormData formData = FormData.fromMap({
|
||||
"audio": await MultipartFile.fromFile(
|
||||
filePath,
|
||||
filename: "rekaman.mp3",
|
||||
),
|
||||
"userId": userId,
|
||||
"qrCodeStr":qrCodeStr,
|
||||
});
|
||||
|
||||
final resp = await postAudio(
|
||||
service: service,
|
||||
formData: formData,
|
||||
);
|
||||
|
||||
final result = List<VoiceToTextModel>.empty(growable: true);
|
||||
resp['data'].forEach((e) {
|
||||
final model = VoiceToTextModel.fromJson(e);
|
||||
result.add(model);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user