feat: 1,调试代码增加说明 2,降噪声音处理 3,新增调试服务器延迟添加
This commit is contained in:
parent
2ee6782714
commit
e4534e8a28
@ -53,6 +53,8 @@ FutureOr<void> main() async {
|
||||
DeBug.showFloatWidget();
|
||||
}
|
||||
});
|
||||
|
||||
//ToDo: 增加对讲调试、正式可删除
|
||||
runApp(MultiProvider(providers: [
|
||||
ChangeNotifierProvider(create: (_) => DebugInfoModel()),
|
||||
], child: MyApp(isLogin: isLogin)));
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
//ToDo: 增加对讲调试、正式可删除
|
||||
class DebugInfoModel with ChangeNotifier {
|
||||
int _recvDataRate = 0;
|
||||
int _recvPacketCount = 0;
|
||||
|
||||
@ -217,6 +217,7 @@ class StartChartManage {
|
||||
/// 设置数据接收回调
|
||||
_onReceiveData(_udpSocket!, Get.context!);
|
||||
|
||||
//ToDo: 增加对讲调试、正式可删除
|
||||
// 每秒重置数据速率
|
||||
Timer.periodic(Duration(seconds: 1), (Timer t) {
|
||||
UdpTalkDataHandler().resetDataRates();
|
||||
@ -703,6 +704,8 @@ class StartChartManage {
|
||||
'❌Udp send data error----> $result ${message.length}');
|
||||
// _udpSocket = null;
|
||||
}
|
||||
|
||||
//ToDo: 增加对讲调试、正式可删除
|
||||
UdpTalkDataHandler().updateSendDataRate(message.length);
|
||||
|
||||
// 更新调试信息
|
||||
@ -911,6 +914,8 @@ class StartChartManage {
|
||||
try {
|
||||
if (dg?.data != null) {
|
||||
final deserialize = ScpMessage.deserialize(dg!.data);
|
||||
|
||||
//ToDo: 增加对讲调试、正式可删除
|
||||
UdpTalkDataHandler().updateRecvDataRate(dg.data.length);
|
||||
|
||||
// 更新调试信息
|
||||
|
||||
@ -597,7 +597,7 @@ class TalkViewLogic extends BaseGetXController {
|
||||
final List<int> processedList = [];
|
||||
for (int pcmVal in pcmList) {
|
||||
// 简单的降噪示例:将小于阈值的信号置为0
|
||||
if (pcmVal.abs() < 500) {
|
||||
if (pcmVal.abs() < 300) {
|
||||
pcmVal = 0;
|
||||
}
|
||||
processedList.add(pcmVal);
|
||||
|
||||
@ -1,26 +1,19 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:star_lock/flavors.dart';
|
||||
import 'package:star_lock/talk/call/callTalk.dart';
|
||||
import 'package:star_lock/talk/startChart/constant/talk_status.dart';
|
||||
import 'package:star_lock/talk/startChart/handle/impl/debug_Info_model.dart';
|
||||
import 'package:star_lock/talk/startChart/handle/impl/udp_talk_data_handler.dart';
|
||||
|
||||
import 'package:star_lock/talk/startChart/views/talkView/talk_view_logic.dart';
|
||||
import 'package:star_lock/talk/startChart/views/talkView/talk_view_state.dart';
|
||||
import 'package:star_lock/talk/udp/udp_manage.dart';
|
||||
|
||||
import '../../../../app_settings/app_colors.dart';
|
||||
import '../../../../tools/showTFView.dart';
|
||||
@ -36,6 +29,7 @@ class _TalkViewPageState extends State<TalkViewPage>
|
||||
with TickerProviderStateMixin {
|
||||
final TalkViewLogic logic = Get.put(TalkViewLogic());
|
||||
final TalkViewState state = Get.find<TalkViewLogic>().state;
|
||||
late Stream<int> _latencyStream;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -61,6 +55,31 @@ class _TalkViewPageState extends State<TalkViewPage>
|
||||
state.animationController.forward();
|
||||
}
|
||||
});
|
||||
|
||||
_latencyStream = measureServerLatencyStream(F.apiPrefix); // 替换为你的服务器地址
|
||||
}
|
||||
|
||||
Stream<int> measureServerLatencyStream(String url) async* {
|
||||
while (true) {
|
||||
final latency = await measureServerLatency(url);
|
||||
yield latency;
|
||||
await Future.delayed(Duration(seconds: 1)); // 每秒测量一次
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> measureServerLatency(String url) async {
|
||||
final Stopwatch stopwatch = Stopwatch()..start();
|
||||
try {
|
||||
final http.Response response = await http.get(Uri.parse(url));
|
||||
if (response.statusCode == 200) {
|
||||
stopwatch.stop();
|
||||
return stopwatch.elapsedMilliseconds;
|
||||
} else {
|
||||
return -1; // 表示请求失败
|
||||
}
|
||||
} catch (e) {
|
||||
return -1; // 表示请求失败
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@ -78,26 +97,26 @@ class _TalkViewPageState extends State<TalkViewPage>
|
||||
children: <Widget>[
|
||||
Obx(
|
||||
() {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final screenHeight = MediaQuery.of(context).size.height;
|
||||
final double screenWidth = MediaQuery.of(context).size.width;
|
||||
final double screenHeight = MediaQuery.of(context).size.height;
|
||||
|
||||
final logicalWidth = MediaQuery.of(context).size.width;
|
||||
final logicalHeight = MediaQuery.of(context).size.height;
|
||||
final devicePixelRatio =
|
||||
final double logicalWidth = MediaQuery.of(context).size.width;
|
||||
final double logicalHeight = MediaQuery.of(context).size.height;
|
||||
final double devicePixelRatio =
|
||||
MediaQuery.of(context).devicePixelRatio;
|
||||
|
||||
// 计算物理像素值
|
||||
final physicalWidth = logicalWidth * devicePixelRatio;
|
||||
final physicalHeight = logicalHeight * devicePixelRatio;
|
||||
final double physicalWidth = logicalWidth * devicePixelRatio;
|
||||
final double physicalHeight = logicalHeight * devicePixelRatio;
|
||||
|
||||
// 旋转后的图片尺寸
|
||||
final rotatedImageWidth = 480; // 原始高度
|
||||
final rotatedImageHeight = 864; // 原始宽度
|
||||
const int rotatedImageWidth = 480; // 原始高度
|
||||
const int rotatedImageHeight = 864; // 原始宽度
|
||||
|
||||
// 计算缩放比例
|
||||
final scaleWidth = physicalWidth / rotatedImageWidth;
|
||||
final scaleHeight = physicalHeight / rotatedImageHeight;
|
||||
final scale = max(scaleWidth, scaleHeight); // 选择较大的缩放比例
|
||||
final double scaleWidth = physicalWidth / rotatedImageWidth;
|
||||
final double scaleHeight = physicalHeight / rotatedImageHeight;
|
||||
max(scaleWidth, scaleHeight); // 选择较大的缩放比例
|
||||
|
||||
return state.listData.value.isEmpty
|
||||
? Image.asset(
|
||||
@ -221,7 +240,7 @@ class _TalkViewPageState extends State<TalkViewPage>
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
children: <Widget>[
|
||||
Icon(Icons.mic, color: Colors.white, size: 24.w),
|
||||
SizedBox(width: 10.w),
|
||||
Text(
|
||||
@ -235,6 +254,7 @@ class _TalkViewPageState extends State<TalkViewPage>
|
||||
),
|
||||
)
|
||||
: Container()),
|
||||
//ToDo: 增加对讲调试、正式可删除
|
||||
Visibility(
|
||||
visible: true,
|
||||
child: Positioned(
|
||||
@ -250,7 +270,7 @@ class _TalkViewPageState extends State<TalkViewPage>
|
||||
Widget? child) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'recv ${debugInfo.recvDataRate}KB/s [${debugInfo.recvPacketCount}]',
|
||||
style: const TextStyle(
|
||||
@ -267,6 +287,40 @@ class _TalkViewPageState extends State<TalkViewPage>
|
||||
),
|
||||
),
|
||||
)),
|
||||
// 添加服务器延迟检测
|
||||
Positioned(
|
||||
top: 120,
|
||||
left: 20,
|
||||
right: 20,
|
||||
child: Container(
|
||||
height: 50,
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: StreamBuilder<int>(
|
||||
stream: _latencyStream,
|
||||
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Text(
|
||||
'检测服务器延迟中...',
|
||||
style: TextStyle(color: Colors.white),
|
||||
);
|
||||
} else if (snapshot.hasError ||
|
||||
!snapshot.hasData ||
|
||||
snapshot.data == -1) {
|
||||
return const Text(
|
||||
'服务器延迟检测失败',
|
||||
style: TextStyle(color: Colors.white),
|
||||
);
|
||||
} else {
|
||||
return Text(
|
||||
'服务器延迟: ${snapshot.data} ms',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user