feat: 调整安卓声音卡顿现象

This commit is contained in:
“DaisyWu” 2025-02-21 14:30:21 +08:00
parent e1943d26d9
commit 35d22fd8ab
2 changed files with 25 additions and 16 deletions

View File

@ -81,6 +81,7 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
// //
Future<void> _showTalkRequestNotification( Future<void> _showTalkRequestNotification(
{required String talkObjectName}) async { {required String talkObjectName}) async {
if (Platform.isAndroid) {
final Map<String, dynamic> message = { final Map<String, dynamic> message = {
'platform': 'all', 'platform': 'all',
'audience': 'all', 'audience': 'all',
@ -97,6 +98,7 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
}; };
XSJPushProvider().showCustomNotification(message); XSJPushProvider().showCustomNotification(message);
}
/* /*
const AndroidNotificationDetails androidPlatformChannelSpecifics = const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails('1', 'flutter_channel', AndroidNotificationDetails('1', 'flutter_channel',

View File

@ -3,6 +3,7 @@ import 'dart:io';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'dart:math'; // Import the math package to use sqrt import 'dart:math'; // Import the math package to use sqrt
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_pcm_sound/flutter_pcm_sound.dart'; import 'package:flutter_pcm_sound/flutter_pcm_sound.dart';
@ -576,12 +577,18 @@ class TalkViewLogic extends BaseGetXController {
} }
} }
//
Future<void> _onFrame(List<int> frame) async { Future<void> _onFrame(List<int> frame) async {
// 线
// final processedFrame = await compute(preprocessAudio, frame);
// final list = listLinearToALaw(processedFrame);
final List<int> processedFrame = preprocessAudio(frame); final List<int> processedFrame = preprocessAudio(frame);
final List<int> list = listLinearToALaw(processedFrame); final List<int> list = listLinearToALaw(processedFrame);
final int ms = DateTime.now().millisecondsSinceEpoch - final int ms = DateTime.now().millisecondsSinceEpoch -
state.startRecordingAudioTime.value.millisecondsSinceEpoch; state.startRecordingAudioTime.value.millisecondsSinceEpoch;
//
// UDP
await StartChartManage().sendTalkDataMessage( await StartChartManage().sendTalkDataMessage(
talkData: TalkData( talkData: TalkData(
content: list, content: list,
@ -591,8 +598,8 @@ class TalkViewLogic extends BaseGetXController {
); );
} }
//
void _onError(VoiceProcessorException error) { void _onError(VoiceProcessorException error) {
// state.errorMessage.value = error.message!;
AppLog.log(error.message!); AppLog.log(error.message!);
} }
@ -601,7 +608,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() < 300) { if (pcmVal.abs() < 200) {
pcmVal = 0; pcmVal = 0;
} }
processedList.add(pcmVal); processedList.add(pcmVal);