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,22 +81,24 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
// //
Future<void> _showTalkRequestNotification( Future<void> _showTalkRequestNotification(
{required String talkObjectName}) async { {required String talkObjectName}) async {
final Map<String, dynamic> message = { if (Platform.isAndroid) {
'platform': 'all', final Map<String, dynamic> message = {
'audience': 'all', 'platform': 'all',
'notification': <String, Map<String, Object>>{ 'audience': 'all',
'android': <String, Object>{ 'notification': <String, Map<String, Object>>{
'title': '呼叫提醒'.tr, 'android': <String, Object>{
'alert': '${'收到来自'.tr}($talkObjectName)${'锁的呼叫'.tr}', 'title': '呼叫提醒'.tr,
'extras': <String, String>{ 'alert': '${'收到来自'.tr}($talkObjectName)${'锁的呼叫'.tr}',
'image_url': 'extras': <String, String>{
'https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=视频通话图标&step_word=&hs=0&pn=18&spn=0&di=7456461798821068801&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=undefined&cs=3670633426%2C2210940696&os=2119936476%2C3383901310&simid=3670633426%2C2210940696&adpicid=0&lpn=0&ln=1216&fr=&fmq=1738909566404_R&fm=&ic=undefined&s=undefined&hd=undefined&latest=undefined&copyright=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&ist=&jit=&cg=&bdtype=0&oriquery=&objurl=https%3A%2F%2Ftenfei03.cfp.cn%2Fcreative%2Fvcg%2Fnowarter800%2Fnew%2FVCG211249198901.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bev2_z%26e3Bv54AzdH3Fv6jwptejAzdH3F8dnla9lla0&gsm=1e&rpstart=0&rpnum=0&islist=&querylist=&nojc=undefined&dyTabStr=MCwxMiwzLDEsMiwxMyw3LDYsNSw5&lid=9610633549467928081' 'image_url':
'https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=视频通话图标&step_word=&hs=0&pn=18&spn=0&di=7456461798821068801&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=undefined&cs=3670633426%2C2210940696&os=2119936476%2C3383901310&simid=3670633426%2C2210940696&adpicid=0&lpn=0&ln=1216&fr=&fmq=1738909566404_R&fm=&ic=undefined&s=undefined&hd=undefined&latest=undefined&copyright=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&ist=&jit=&cg=&bdtype=0&oriquery=&objurl=https%3A%2F%2Ftenfei03.cfp.cn%2Fcreative%2Fvcg%2Fnowarter800%2Fnew%2FVCG211249198901.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bev2_z%26e3Bv54AzdH3Fv6jwptejAzdH3F8dnla9lla0&gsm=1e&rpstart=0&rpnum=0&islist=&querylist=&nojc=undefined&dyTabStr=MCwxMiwzLDEsMiwxMyw3LDYsNSw5&lid=9610633549467928081'
}
} }
} }
} };
};
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);