build: v1.3.0+37

This commit is contained in:
fanpeng 2025-07-07 17:23:51 +08:00
parent 89fca5a450
commit a24b367a5b
4 changed files with 67 additions and 68 deletions

View File

@ -31,7 +31,7 @@
return 'XHJ' return 'XHJ'
} }
// #endif // #endif
return 'DEV' return 'XHJ'
} }
}, },
computed: { computed: {

View File

@ -250,7 +250,7 @@
return data return data
}) })
const cleanupResources = () => { const cleanupResources = async () => {
if (cleanupCalled.value) return if (cleanupCalled.value) return
cleanupCalled.value = true cleanupCalled.value = true
@ -263,8 +263,8 @@
} }
releaseRecord() releaseRecord()
if (deviceInfo.value) { if (deviceInfo.value) {
stopSendServiceFunction(`${deviceInfo.value.productId}/${deviceInfo.value.deviceName}`) await stopSendServiceFunction(`${deviceInfo.value.productId}/${deviceInfo.value.deviceName}`)
stopServiceFunction(`${deviceInfo.value.productId}/${deviceInfo.value.deviceName}`) await stopServiceFunction(`${deviceInfo.value.productId}/${deviceInfo.value.deviceName}`)
} }
// #endif // #endif
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
@ -545,8 +545,12 @@
// #endif // #endif
} }
const callback = audioData => { const callback = async audioData => {
dataSendFunction(`${deviceInfo.value.productId}/${deviceInfo.value.deviceName}`, audioData) console.log('传输数据', audioData)
await dataSendFunction(
`${deviceInfo.value.productId}/${deviceInfo.value.deviceName}`,
audioData
)
} }
const handlePlaySuccess = () => { const handlePlaySuccess = () => {

View File

@ -49,62 +49,69 @@ public class AudioRecorderManager: NSObject {
return return
} }
let session = AVAudioSession.sharedInstance() if audioEngine == nil {
do { let session = AVAudioSession.sharedInstance()
try session.setCategory(.playAndRecord, mode: .default, options: .defaultToSpeaker) do {
try session.setPreferredSampleRate(16000.0) try session.setCategory(.playAndRecord, mode: .default, options: .defaultToSpeaker)
try session.setPreferredInputNumberOfChannels(1) try session.setPreferredSampleRate(16000.0)
try session.setActive(true) try session.setPreferredInputNumberOfChannels(1)
} catch { try session.setActive(true)
completion(nil, false, "Failed to set up audio session: \(error.localizedDescription)") } catch {
return completion(nil, false, "Failed to set up audio session: \(error.localizedDescription)")
} return
}
audioEngine = AVAudioEngine() audioEngine = AVAudioEngine()
guard let audioEngine = audioEngine else { guard let audioEngine = audioEngine else {
completion(nil, false, "Failed to create audio engine") completion(nil, false, "Failed to create audio engine")
return return
} }
let inputNode = audioEngine.inputNode let inputNode = audioEngine.inputNode
let inputFormat = inputNode.outputFormat(forBus: 0) let inputFormat = inputNode.outputFormat(forBus: 0)
var outputFormatDescription = AudioStreamBasicDescription( var outputFormatDescription = AudioStreamBasicDescription(
mSampleRate: 16000.0, mSampleRate: 16000.0,
mFormatID: kAudioFormatMPEG4AAC, mFormatID: kAudioFormatMPEG4AAC,
mFormatFlags: 2, mFormatFlags: 2,
mBytesPerPacket: 0, mBytesPerPacket: 0,
mFramesPerPacket: 1024, mFramesPerPacket: 1024,
mBytesPerFrame: 0, mBytesPerFrame: 0,
mChannelsPerFrame: 1, mChannelsPerFrame: 1,
mBitsPerChannel: 0, mBitsPerChannel: 0,
mReserved: 0 mReserved: 0
) )
guard let outputFormat = AVAudioFormat(streamDescription: &outputFormatDescription) else { guard let outputFormat = AVAudioFormat(streamDescription: &outputFormatDescription) else {
completion(nil, false, "Failed to create output audio format") completion(nil, false, "Failed to create output audio format")
return return
} }
guard let converter = AVAudioConverter(from: inputFormat, to: outputFormat) else { guard let converter = AVAudioConverter(from: inputFormat, to: outputFormat) else {
completion(nil, false, "Failed to create audio converter") completion(nil, false, "Failed to create audio converter")
return return
} }
self.audioConverter = converter self.audioConverter = converter
self.aacBuffer = AVAudioCompressedBuffer( self.aacBuffer = AVAudioCompressedBuffer(
format: outputFormat, format: outputFormat,
packetCapacity: 1, packetCapacity: 1,
maximumPacketSize: converter.maximumOutputPacketSize maximumPacketSize: converter.maximumOutputPacketSize
) )
inputNode.installTap(onBus: 0, bufferSize: 1024, format: inputFormat) { [weak self] (pcmBuffer, when) in inputNode.installTap(onBus: 0, bufferSize: 1024, format: inputFormat) { [weak self] (pcmBuffer, when) in
guard let self = self, self.isRecording else { return } guard let self = self, self.isRecording else { return }
self.convert(pcmBuffer: pcmBuffer, completion: completion) self.convert(pcmBuffer: pcmBuffer, completion: completion)
} }
do {
audioEngine.prepare() audioEngine.prepare()
}
do {
guard let audioEngine = audioEngine else {
completion(nil, false, "Audio engine not initialized.")
return
}
try audioEngine.start() try audioEngine.start()
self.isRecording = true self.isRecording = true
completion(nil, true, "Recording started") completion(nil, true, "Recording started")
@ -193,19 +200,7 @@ public class AudioRecorderManager: NSObject {
return return
} }
self.isRecording = false self.isRecording = false
audioEngine?.stop() audioEngine?.stop()
audioEngine?.inputNode.removeTap(onBus: 0)
audioEngine = nil
audioConverter = nil
aacBuffer = nil
do {
try AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
} catch {
print("Failed to deactivate audio session: \(error)")
}
completion(true, "Recording stopped", "") completion(true, "Recording stopped", "")
} }

View File

@ -132,7 +132,7 @@ export const runSendServiceFunction = async function (
crypto: boolean crypto: boolean
): Promise<Result> { ): Promise<Result> {
try { try {
const result = runSendService(id, cmd, crypto) const result = await runSendService(id, cmd, crypto)
console.log('开始发送服务', result) console.log('开始发送服务', result)
return { return {
code: 0, code: 0,
@ -178,8 +178,8 @@ export const dataSendFunction = async function (id: string, data: Array<number>)
} }
try { try {
const result = dataSend(id, buffer, data.length) const result = await dataSend(id, buffer, data.length)
// console.log('发送数据结果', result) console.log('发送数据结果', result)
XP2PDataHelper.deallocateBytes(buffer) XP2PDataHelper.deallocateBytes(buffer)