Browse Source

修复opus文件不保存问题

weicu
fdp 10 months ago
parent
commit
2d4e5782cb
  1. 27
      local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleCommandSender.kt
  2. 29
      local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt

27
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")
// 声道模式描述

29
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(),

Loading…
Cancel
Save