|
|
|
@ -1,13 +1,16 @@ |
|
|
|
import 'dart:convert'; |
|
|
|
import 'dart:io'; |
|
|
|
|
|
|
|
import 'package:file_picker/file_picker.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:http/http.dart' as http; |
|
|
|
import 'package:just_audio/just_audio.dart'; |
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
|
|
|
|
|
import '../../../core/utils/logger.dart'; |
|
|
|
import '../../../core/utils/upload_oss.dart'; |
|
|
|
import '../../../data/services/db/sqflite_api.dart'; |
|
|
|
|
|
|
|
@ -16,18 +19,33 @@ class MeetingController extends GetxController { |
|
|
|
final AudioPlayer _audioPlayer = AudioPlayer(); |
|
|
|
|
|
|
|
// 是否还有更多数据 |
|
|
|
bool isLoadingMore = true; |
|
|
|
bool isGetMore = true; |
|
|
|
bool isLoading = false; |
|
|
|
int page = 1; |
|
|
|
int addQuantity = 0; |
|
|
|
|
|
|
|
TextEditingController titleController = TextEditingController(); // 录音标题 |
|
|
|
|
|
|
|
RxList dataList = [].obs; |
|
|
|
|
|
|
|
List dataListTask = []; |
|
|
|
bool isDisposed = false; |
|
|
|
|
|
|
|
final String _appid = '2316081933'; |
|
|
|
final String _token = 'mcJTh6OelBqU_L78lgGd77Nyrc_-5-En'; |
|
|
|
final String _cluster = 'volc_auc_meeting_flash'; |
|
|
|
final String _serviceUrl = 'https://openspeech.bytedance.com/api/v1/auc'; |
|
|
|
Map<String, String> _headers = {}; |
|
|
|
|
|
|
|
@override |
|
|
|
void onInit() { |
|
|
|
super.onInit(); |
|
|
|
listController.addListener(_onScroll); |
|
|
|
Permission.storage.request(); |
|
|
|
_headers = { |
|
|
|
'Authorization': 'Bearer; $_token', |
|
|
|
'Content-Type': 'application/json', |
|
|
|
}; |
|
|
|
_getDataList(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -36,13 +54,16 @@ class MeetingController extends GetxController { |
|
|
|
listController.dispose(); |
|
|
|
titleController.dispose(); |
|
|
|
_audioPlayer.dispose(); |
|
|
|
isDisposed = true; |
|
|
|
super.onClose(); |
|
|
|
} |
|
|
|
|
|
|
|
void _onScroll() { |
|
|
|
if (isLoadingMore && |
|
|
|
if (isGetMore && |
|
|
|
!isLoading && |
|
|
|
listController.position.pixels >= |
|
|
|
listController.position.maxScrollExtent - 100) { |
|
|
|
isLoading = true; |
|
|
|
page++; |
|
|
|
_getDataList(); |
|
|
|
} |
|
|
|
@ -50,13 +71,16 @@ class MeetingController extends GetxController { |
|
|
|
|
|
|
|
// 请求本地数据 |
|
|
|
void _getDataList() async { |
|
|
|
List list = await SqfliteApi.getMeetingList(page); |
|
|
|
List list = await SqfliteApi.getMeetingList((page - 1) * 10 + addQuantity); |
|
|
|
dataList.addAll(list); |
|
|
|
queryDataListTask(list); |
|
|
|
addQuantity = 0; |
|
|
|
if (list.length < 10) { |
|
|
|
isLoadingMore = false; |
|
|
|
isGetMore = false; |
|
|
|
} else { |
|
|
|
isLoadingMore = true; |
|
|
|
isGetMore = true; |
|
|
|
} |
|
|
|
isLoading = false; |
|
|
|
} |
|
|
|
|
|
|
|
void addAudio() async { |
|
|
|
@ -79,15 +103,17 @@ class MeetingController extends GetxController { |
|
|
|
'seconds': seconds, |
|
|
|
'filepath': filePath, |
|
|
|
'audiourl': audiourl, |
|
|
|
'tasktype': 0, |
|
|
|
'creationtime': creationTime, |
|
|
|
}; |
|
|
|
final meetingId = await SqfliteApi.insertMeeting(data); |
|
|
|
if (meetingId != null) { |
|
|
|
dataList.insert(0, { |
|
|
|
'id': meetingId, |
|
|
|
'tasktype': 0, |
|
|
|
'taskid': '', |
|
|
|
...data, |
|
|
|
}); |
|
|
|
addQuantity++; |
|
|
|
} |
|
|
|
} |
|
|
|
EasyLoading.dismiss(); |
|
|
|
@ -104,7 +130,7 @@ class MeetingController extends GetxController { |
|
|
|
// 修改标题 |
|
|
|
void editMeetingTitle(int id, String title) async { |
|
|
|
if (title.isNotEmpty) { |
|
|
|
SqfliteApi.editMeetingTitle(id, title); |
|
|
|
SqfliteApi.editMeetingTitle(id, {'title': title}); |
|
|
|
int index = dataList.indexWhere((item) => item['id'] == id); |
|
|
|
if (index != -1) { |
|
|
|
final dataMap = Map<String, dynamic>.from(dataList[index]); |
|
|
|
@ -121,6 +147,7 @@ class MeetingController extends GetxController { |
|
|
|
// 删除数据库中的记录 |
|
|
|
SqfliteApi.deleteMeeting(id); |
|
|
|
_deleteFile(filepath); |
|
|
|
addQuantity--; |
|
|
|
} |
|
|
|
|
|
|
|
// 删除文件 |
|
|
|
@ -131,4 +158,107 @@ class MeetingController extends GetxController { |
|
|
|
await file.delete(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 查询转写状态 |
|
|
|
void queryDataListTask(List list, {bool isAdd = true}) { |
|
|
|
for (var element in List.from(list)) { |
|
|
|
if (element['tasktype'] == 1) { |
|
|
|
if (isAdd) { |
|
|
|
dataListTask.add(element); |
|
|
|
} |
|
|
|
final taskId = element['taskid']; |
|
|
|
_fileRecognize(element['id'], taskId); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> _fileRecognize(int id, String taskId) async { |
|
|
|
try { |
|
|
|
final startTime = DateTime.now().millisecondsSinceEpoch; |
|
|
|
|
|
|
|
if (isDisposed) return; |
|
|
|
var respDic = await _queryTask(taskId); |
|
|
|
var code = respDic['resp']['code'] as int; |
|
|
|
|
|
|
|
if (code == 1000) { |
|
|
|
await SqfliteApi.editMeetingTitle(id, {'tasktype': 2}); |
|
|
|
int index = dataList.indexWhere((item) => item['id'] == id); |
|
|
|
if (index != -1) { |
|
|
|
final dataMap = Map<String, dynamic>.from(dataList[index]); |
|
|
|
dataMap['tasktype'] = 2; |
|
|
|
dataList[index] = dataMap; |
|
|
|
int taskIndex = dataListTask.indexWhere((item) => item['id'] == id); |
|
|
|
if (taskIndex != -1) { |
|
|
|
dataListTask.removeAt(taskIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
} else if (code < 2000) { |
|
|
|
Logger.debug("FileRecognize failed"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
while (!isDisposed) { |
|
|
|
await Future.delayed(const Duration(seconds: 2)); |
|
|
|
|
|
|
|
if (isDisposed) return; |
|
|
|
|
|
|
|
respDic = await _queryTask(taskId); |
|
|
|
code = respDic['resp']['code'] as int; |
|
|
|
|
|
|
|
if (code == 1000) { |
|
|
|
await SqfliteApi.editMeetingTitle(id, {'tasktype': 2}); |
|
|
|
int index = dataList.indexWhere((item) => item['id'] == id); |
|
|
|
if (index != -1) { |
|
|
|
final dataMap = Map<String, dynamic>.from(dataList[index]); |
|
|
|
dataMap['tasktype'] = 2; |
|
|
|
dataList[index] = dataMap; |
|
|
|
int taskIndex = dataListTask.indexWhere((item) => item['id'] == id); |
|
|
|
if (taskIndex != -1) { |
|
|
|
dataListTask.removeAt(taskIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
} else if (code < 2000) { |
|
|
|
Logger.debug("FileRecognize failed"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
final currentTime = DateTime.now().millisecondsSinceEpoch; |
|
|
|
if (currentTime - startTime > 300 * 1000) { |
|
|
|
Logger.debug('wait time exceeds 300s'); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
Logger.error('Error occurred: ${e.toString()}'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Future<Map<String, dynamic>> _queryTask(String taskId) async { |
|
|
|
final queryBody = jsonEncode({ |
|
|
|
"appid": _appid, |
|
|
|
"token": _token, |
|
|
|
"id": taskId, |
|
|
|
"cluster": _cluster, |
|
|
|
}); |
|
|
|
|
|
|
|
try { |
|
|
|
final response = await http.post( |
|
|
|
Uri.parse('$_serviceUrl/query'), |
|
|
|
headers: _headers, |
|
|
|
body: queryBody, |
|
|
|
); |
|
|
|
|
|
|
|
if (response.statusCode != 200) { |
|
|
|
throw Exception('Query failed with status: ${response.statusCode}'); |
|
|
|
} |
|
|
|
|
|
|
|
final respDic = jsonDecode(response.body); |
|
|
|
return respDic; |
|
|
|
} catch (e) { |
|
|
|
Logger.error('Query error: ${e.toString()}'); |
|
|
|
rethrow; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|