From a2a209000a5a55b1767520bc9c2fce931bd610f6 Mon Sep 17 00:00:00 2001 From: fdp <1286779656@qq.com> Date: Tue, 9 Dec 2025 12:36:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dopus=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8D=E4=BF=9D=E5=AD=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ble_service/BleCommandSender.kt | 27 +---------------- .../yunqiinnovation/ble_service/BleService.kt | 29 +++++++------------ 2 files changed, 11 insertions(+), 45 deletions(-) diff --git a/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleCommandSender.kt b/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleCommandSender.kt index fba29431d..d91351069 100644 --- a/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleCommandSender.kt +++ b/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleCommandSender.kt @@ -85,17 +85,6 @@ class BleCommandSender { */ fun notifyWakeupSignalReceived() - /** - * 获取录音文件对象 - * @return 录音文件对象 - */ - fun getRecordFile(): RecordingFile? - - /** - * 获取重新压缩录音文件对象 - * @return 重新压缩录音文件对象 - */ - fun getRecordFile1(): RecordingFile? } private var callback: CommandSenderCallback? = null @@ -382,21 +371,7 @@ class BleCommandSender { else -> "未知状态($codecStatus)" } - // 处理录音文件 - if (codecStatus == BleConst.CODEC_CONTROL_DECODE_ON || - codecStatus == BleConst.CODEC_CONTROL_A2DP_PLAY || - codecStatus == BleConst.CODEC_CONTROL_CALL_RECORD_PLAY || - codecStatus == BleConst.CODEC_CONTROL_ENCODE_ON - ) { - callback?.getRecordFile1()?.closeFile() - callback?.getRecordFile1()?.creatingFiles() - callback?.getRecordFile()?.closeFile() - callback?.getRecordFile()?.creatingFiles() - } else if (codecStatus == BleConst.CODEC_CONTROL_CLOSE) { - callback?.getRecordFile()?.closeFile() - callback?.getRecordFile1()?.closeFile() - } - + Log.d(TAG, "收到设备响应,channelMode: $channelMode") // 声道模式描述 diff --git a/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt b/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt index 1fc62da1b..10378a4f2 100644 --- a/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt +++ b/local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt @@ -212,10 +212,10 @@ object BleService { scanHandler = Handler(Looper.getMainLooper()) recordfile = RecordingFile(this.context) - recordfile!!.fileName = "不拆分" + recordfile!!.fileName = "耳机端" recordfile1 = RecordingFile(this.context) - recordfile1!!.fileName = "重新压缩" + recordfile1!!.fileName = "手机端" // 初始化Opus音频管理器 if (!opusAudioManager.initialize()) { @@ -325,19 +325,7 @@ object BleService { this@BleService.notifyWakeupSignalReceived() } - /** - * 获取录音文件实例 - */ - override fun getRecordFile(): RecordingFile? { - return recordfile - } - - /** - * 获取录音文件实例1 - */ - override fun getRecordFile1(): RecordingFile? { - return recordfile1 - } + }) } @@ -875,14 +863,14 @@ object BleService { // 统计接收到的字节数 bytesReceivedInCurrentSecond += data.size processAudioData(data) - Log.i(TAG, "lxm--收到音频特征数据, 字节数=${data.size}") + // Log.i(TAG, "lxm--收到音频特征数据, 字节数=${data.size}") } BleConst.CALL_RECEIVE_AUDIO_CHAR_UUID -> { // 统计接收到的字节数 bytesReceivedInCurrentSecond += data.size processAudioData(data) - Log.i(TAG, "lxm--收到通话音频特征数据, 字节数=${data.size}") + //Log.i(TAG, "lxm--收到通话音频特征数据, 字节数=${data.size}") } // 通知特征数据(命令和控制) BleConst.NOTIFY_CHAR_UUID -> { @@ -1119,6 +1107,8 @@ object BleService { sampleRate: Int = 16000, packetSize: Int = 40 ): Boolean { + recordfile?.creatingFiles(); + return opusAudioManager.startDecodeStream(hasHeader, channel, sampleRate, packetSize) } @@ -1204,6 +1194,7 @@ object BleService { if (audioChunk != null) { // 发送音频数据块并等待回调 + recordfile1?.saveAudioDataToWav(audioChunk) sendAudioChunkWithCallback(audioChunk) Thread.sleep(AUDIO_SEND_INTERVAL) } @@ -1259,7 +1250,7 @@ object BleService { isWaitingForWriteCallback = true callWriteChar?.value = chunk - recordfile1?.saveAudioDataToWav(chunk) + //recordfile1?.saveAudioDataAsUtf8Hex(chunk, true) val isSuccess = bluetoothGatt?.writeCharacteristic(callWriteChar) @@ -1439,7 +1430,7 @@ object BleService { fun openA2DPDecoder(channelMode: Int = BleConst.AUDIO_CHANNEL_STEREO): Boolean { Log.i(TAG, "打开A2DP解码器...") startOpusEncodeStream() - + recordfile1?.creatingFiles(); startOpusStreamDecoding(false, 2, 16000, 80) val cmdData = byteArrayOf( BleConst.CODEC_CONTROL_A2DP_PLAY.toByte(),