feat: 1,调试代码增加说明 2,降噪声音处理 3,新增调试服务器延迟添加

This commit is contained in:
“DaisyWu” 2025-01-22 13:55:43 +08:00
parent 2ee6782714
commit e4534e8a28
5 changed files with 86 additions and 24 deletions

View File

@ -53,6 +53,8 @@ FutureOr<void> main() async {
DeBug.showFloatWidget(); DeBug.showFloatWidget();
} }
}); });
//ToDo:
runApp(MultiProvider(providers: [ runApp(MultiProvider(providers: [
ChangeNotifierProvider(create: (_) => DebugInfoModel()), ChangeNotifierProvider(create: (_) => DebugInfoModel()),
], child: MyApp(isLogin: isLogin))); ], child: MyApp(isLogin: isLogin)));

View File

@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
//ToDo:
class DebugInfoModel with ChangeNotifier { class DebugInfoModel with ChangeNotifier {
int _recvDataRate = 0; int _recvDataRate = 0;
int _recvPacketCount = 0; int _recvPacketCount = 0;

View File

@ -217,6 +217,7 @@ class StartChartManage {
/// ///
_onReceiveData(_udpSocket!, Get.context!); _onReceiveData(_udpSocket!, Get.context!);
//ToDo:
// //
Timer.periodic(Duration(seconds: 1), (Timer t) { Timer.periodic(Duration(seconds: 1), (Timer t) {
UdpTalkDataHandler().resetDataRates(); UdpTalkDataHandler().resetDataRates();
@ -703,6 +704,8 @@ class StartChartManage {
'❌Udp send data error----> $result ${message.length}'); '❌Udp send data error----> $result ${message.length}');
// _udpSocket = null; // _udpSocket = null;
} }
//ToDo:
UdpTalkDataHandler().updateSendDataRate(message.length); UdpTalkDataHandler().updateSendDataRate(message.length);
// //
@ -911,6 +914,8 @@ class StartChartManage {
try { try {
if (dg?.data != null) { if (dg?.data != null) {
final deserialize = ScpMessage.deserialize(dg!.data); final deserialize = ScpMessage.deserialize(dg!.data);
//ToDo:
UdpTalkDataHandler().updateRecvDataRate(dg.data.length); UdpTalkDataHandler().updateRecvDataRate(dg.data.length);
// //

View File

@ -597,7 +597,7 @@ class TalkViewLogic extends BaseGetXController {
final List<int> processedList = []; final List<int> processedList = [];
for (int pcmVal in pcmList) { for (int pcmVal in pcmList) {
// 0 // 0
if (pcmVal.abs() < 500) { if (pcmVal.abs() < 300) {
pcmVal = 0; pcmVal = 0;
} }
processedList.add(pcmVal); processedList.add(pcmVal);

View File

@ -1,26 +1,19 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math'; import 'dart:math';
import 'dart:ui';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:star_lock/flavors.dart';
import 'package:star_lock/talk/call/callTalk.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/constant/talk_status.dart';
import 'package:star_lock/talk/startChart/handle/impl/debug_Info_model.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/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_logic.dart';
import 'package:star_lock/talk/startChart/views/talkView/talk_view_state.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 '../../../../app_settings/app_colors.dart';
import '../../../../tools/showTFView.dart'; import '../../../../tools/showTFView.dart';
@ -36,6 +29,7 @@ class _TalkViewPageState extends State<TalkViewPage>
with TickerProviderStateMixin { with TickerProviderStateMixin {
final TalkViewLogic logic = Get.put(TalkViewLogic()); final TalkViewLogic logic = Get.put(TalkViewLogic());
final TalkViewState state = Get.find<TalkViewLogic>().state; final TalkViewState state = Get.find<TalkViewLogic>().state;
late Stream<int> _latencyStream;
@override @override
void initState() { void initState() {
@ -61,6 +55,31 @@ class _TalkViewPageState extends State<TalkViewPage>
state.animationController.forward(); 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 @override
@ -78,26 +97,26 @@ class _TalkViewPageState extends State<TalkViewPage>
children: <Widget>[ children: <Widget>[
Obx( Obx(
() { () {
final screenWidth = MediaQuery.of(context).size.width; final double screenWidth = MediaQuery.of(context).size.width;
final screenHeight = MediaQuery.of(context).size.height; final double screenHeight = MediaQuery.of(context).size.height;
final logicalWidth = MediaQuery.of(context).size.width; final double logicalWidth = MediaQuery.of(context).size.width;
final logicalHeight = MediaQuery.of(context).size.height; final double logicalHeight = MediaQuery.of(context).size.height;
final devicePixelRatio = final double devicePixelRatio =
MediaQuery.of(context).devicePixelRatio; MediaQuery.of(context).devicePixelRatio;
// //
final physicalWidth = logicalWidth * devicePixelRatio; final double physicalWidth = logicalWidth * devicePixelRatio;
final physicalHeight = logicalHeight * devicePixelRatio; final double physicalHeight = logicalHeight * devicePixelRatio;
// //
final rotatedImageWidth = 480; // const int rotatedImageWidth = 480; //
final rotatedImageHeight = 864; // const int rotatedImageHeight = 864; //
// //
final scaleWidth = physicalWidth / rotatedImageWidth; final double scaleWidth = physicalWidth / rotatedImageWidth;
final scaleHeight = physicalHeight / rotatedImageHeight; final double scaleHeight = physicalHeight / rotatedImageHeight;
final scale = max(scaleWidth, scaleHeight); // max(scaleWidth, scaleHeight); //
return state.listData.value.isEmpty return state.listData.value.isEmpty
? Image.asset( ? Image.asset(
@ -221,7 +240,7 @@ class _TalkViewPageState extends State<TalkViewPage>
), ),
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: <Widget>[
Icon(Icons.mic, color: Colors.white, size: 24.w), Icon(Icons.mic, color: Colors.white, size: 24.w),
SizedBox(width: 10.w), SizedBox(width: 10.w),
Text( Text(
@ -235,6 +254,7 @@ class _TalkViewPageState extends State<TalkViewPage>
), ),
) )
: Container()), : Container()),
//ToDo:
Visibility( Visibility(
visible: true, visible: true,
child: Positioned( child: Positioned(
@ -250,7 +270,7 @@ class _TalkViewPageState extends State<TalkViewPage>
Widget? child) { Widget? child) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: <Widget>[
Text( Text(
'recv ${debugInfo.recvDataRate}KB/s [${debugInfo.recvPacketCount}]', 'recv ${debugInfo.recvDataRate}KB/s [${debugInfo.recvPacketCount}]',
style: const TextStyle( 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),
);
}
},
),
),
),
], ],
), ),
), ),