From a6773da4fd47e11126f3884343cb8fd1c732c10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=B0=91=E9=98=B3?= <786612630@qq.com> Date: Fri, 22 Dec 2023 14:26:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitoring/lockMonitoring_page.dart | 63 +++++++++++-------- star_lock/lib/talk/call/callTalk.dart | 6 +- .../udp/io_protocol/udp_mainProtocol.dart | 2 + 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart b/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart index 0dd7a6d5..ad539497 100644 --- a/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart +++ b/star_lock/lib/main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart @@ -223,6 +223,8 @@ class _LockMonitoringPageState extends State { }), bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png", "开锁", AppColors.mainColor, () { + + // _playRecording(); showDeletPasswordAlertDialog(context); }) ]); @@ -231,34 +233,22 @@ class _LockMonitoringPageState extends State { String getAnswerBtnImg() { switch (state.udpStatus.value) { case 8: - { return "images/main/icon_lockDetail_monitoringUnTalkback.png"; - } case 9: - { return "images/main/icon_lockDetail_monitoringTalkback.png"; - } default: - { return "images/main/icon_lockDetail_monitoringAnswerCalls.png"; - } } } String getAnswerBtnName() { switch (state.udpStatus.value) { case 8: - { return "长按说话"; - } case 9: - { return "松开发送"; - } default: - { return "接听"; - } } } @@ -356,6 +346,9 @@ class _LockMonitoringPageState extends State { await recorder.startRecorder( toFile: filePath, codec: Codec.pcm16WAV, + bitRate: 8000, + numChannels: 1, + sampleRate: 8000, ); } @@ -363,9 +356,6 @@ class _LockMonitoringPageState extends State { _stopRecording() async { await recorder.stopRecorder(); - var userMobileIP = await NetworkInfo().getWifiIP(); - var userMobile = await Storage.getMobile(); - // final file = File(filePath); File file = File(filePath); // 使用 create 方法创建文件 @@ -374,23 +364,13 @@ class _LockMonitoringPageState extends State { final List bytes = await file.readAsBytes(); print('Recorded audio bytes.length:${bytes.length} bytes: $bytes'); - // 刚进来是接听状态,然后改为长按对讲 - UDPSenderManage.sendMainProtocol( - command: 150, - commandTypeIsCalling: 1, - subCommand: 8, - lockID: UDPManage().lockId, - lockIP: UDPManage().host, - userMobile: userMobile, - userMobileIP: userMobileIP, - endData: bytes - ); + _sendRecordData(bytes); } } Future getFilePath() async { final directory = await getApplicationDocumentsDirectory(); - final filePath = '${directory.path}/recording.mp3'; + final filePath = '${directory.path}/recording.wav'; // 创建文件 File file = File(filePath); @@ -425,4 +405,33 @@ class _LockMonitoringPageState extends State { // _stopPlaying() async { // await player.stopPlayer(); // } + + _sendRecordData(List bytes) async { + // 刚进来是接听状态,然后改为长按对讲 + var userMobileIP = await NetworkInfo().getWifiIP(); + var userMobile = await Storage.getMobile(); + + // 57 + List topBytes = [ + 1, 1, 1, 1, // 时间戳 + 1, 0, // 音频 + 1, 0, // 帧序号 + 64, 0, 0, 0, // 帧长度 + 1, 0, // 总包数 + 1, 0, // 当前包号 + 64, 1, // 数据长度 + 176, 4, // 保留 + ]; + UDPSenderManage.sendMainProtocol( + command: 150, + commandTypeIsCalling: 1, + subCommand: 8, + lockID: UDPManage().lockId, + lockIP: UDPManage().host, + userMobile: userMobile, + userMobileIP: userMobileIP, + endData: bytes + ); + } + } diff --git a/star_lock/lib/talk/call/callTalk.dart b/star_lock/lib/talk/call/callTalk.dart index 4651ad0a..4dbedae9 100644 --- a/star_lock/lib/talk/call/callTalk.dart +++ b/star_lock/lib/talk/call/callTalk.dart @@ -26,6 +26,7 @@ class CallTalk { var growableList; bool getFirstFrame = false; //是否得到了第一帧 final FlutterSoundPlayer _audioPlayer = FlutterSoundPlayer(); + Uint8List? allPcmData = Uint8List(0); CallTalk._init() { iframe = IframeInfo(); @@ -53,8 +54,9 @@ class CallTalk { Uint8List pcmData = G711Decoder().g711Decode(g711Data, G711Type.uLaw); // 现在你可以使用 pcmData 进行播放或其他处理 print('得到的pcmData:$pcmData'); - - _playRawData(pcmData); + allPcmData!.addAll(pcmData); + await Future.delayed(const Duration(seconds: 3)); + _playRawData(allPcmData!); } // 视频数据 else { diff --git a/star_lock/lib/talk/udp/io_protocol/udp_mainProtocol.dart b/star_lock/lib/talk/udp/io_protocol/udp_mainProtocol.dart index add59504..0fffeb9b 100644 --- a/star_lock/lib/talk/udp/io_protocol/udp_mainProtocol.dart +++ b/star_lock/lib/talk/udp/io_protocol/udp_mainProtocol.dart @@ -62,6 +62,8 @@ class UDPMainProtocolCommand extends UDPSenderProtocol { data.add(int.parse(element)); }); + data.addAll(endData!); + // print("datadatadata:$data"); return data; }