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'
}
// #endif
return 'DEV'
return 'XHJ'
}
},
computed: {

View File

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

View File

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

View File

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