|
|
@@ -6,8 +6,9 @@ import 'package:electronic_assistant/data/repositories/talk_repository.dart';
|
|
|
import 'package:electronic_assistant/dialog/alert_dialog.dart';
|
|
|
import 'package:electronic_assistant/module/record/constants.dart';
|
|
|
import 'package:electronic_assistant/module/talk/view.dart';
|
|
|
+import 'package:electronic_assistant/utils/http_handler.dart';
|
|
|
import 'package:electronic_assistant/utils/mmkv_util.dart';
|
|
|
-import 'package:flutter/cupertino.dart';
|
|
|
+import 'package:electronic_assistant/utils/toast_util.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
import 'package:record/record.dart';
|
|
|
@@ -53,7 +54,7 @@ class RecordController extends BaseController {
|
|
|
var fileLength = currentRecordFile.lengthSync();
|
|
|
if (currentRecordFile.existsSync() && fileLength > 0) {
|
|
|
_changeRecordStatus(RecordStatus.paused);
|
|
|
- currentDuration.value = await _getPcmDuration(
|
|
|
+ currentDuration.value = _getPcmDuration(
|
|
|
fileLength, recordConfig.sampleRate, 16, recordConfig.numChannels);
|
|
|
}
|
|
|
}
|
|
|
@@ -127,7 +128,7 @@ class RecordController extends BaseController {
|
|
|
recordStream.listen((data) async {
|
|
|
targetFile.writeAsBytesSync(data, mode: FileMode.append);
|
|
|
currentDuration.value = currentDuration.value +
|
|
|
- await _getPcmDuration(data.length, recordConfig.sampleRate, 16,
|
|
|
+ _getPcmDuration(data.length, recordConfig.sampleRate, 16,
|
|
|
recordConfig.numChannels);
|
|
|
}, onDone: () {
|
|
|
_changeRecordStatus(RecordStatus.paused);
|
|
|
@@ -151,8 +152,8 @@ class RecordController extends BaseController {
|
|
|
return file;
|
|
|
}
|
|
|
|
|
|
- Future<double> _getPcmDuration(
|
|
|
- int fileSize, int sampleRate, int bitDepth, int channels) async {
|
|
|
+ double _getPcmDuration(
|
|
|
+ int fileSize, int sampleRate, int bitDepth, int channels) {
|
|
|
final bytesPerSecond = sampleRate * (bitDepth / 8) * channels;
|
|
|
final durationInSeconds = fileSize / bytesPerSecond;
|
|
|
return durationInSeconds;
|
|
|
@@ -187,7 +188,11 @@ class RecordController extends BaseController {
|
|
|
throw Exception("pcm file not found");
|
|
|
}
|
|
|
}).catchError((error) {
|
|
|
- debugPrint(error);
|
|
|
+ if (error is ServerErrorException) {
|
|
|
+ ToastUtil.showToast("${error.message}");
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast("保存失败, 请重试");
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|