gpt4 book ai didi

swift - 音频引擎仅在运行 iOS 10 的设备(iphone 6s)上失败,在所有模拟器设备或真实设备上运行良好,直到 iphone 6s

转载 作者:行者123 更新时间:2023-11-28 08:27:34 25 4
gpt4 key购买 nike

我尝试将效果添加到音频文件,它在 iOS 9 上有效,但在 iOS10 中它仅在 iphone 6s 中失败,在旧设备上运行,在模拟器中运行良好,我的信息中确实有隐私使用说明。用于照片、相机和 microfon 的 plist 文件我确实在 audioEngine.mainMixerNode.installTapOnBus 线上收到输卵管错误

2016-09-21 13:08:20.109701 $$$$[557:86076] [central] 54:   ERROR:    [0x16e34f000] >avae> AVAudioNode.mm:751: AUSetFormat: error -10865 
2016-09-21 13:08:20.110111 Tell Your Story[557:86076] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'error -10865'

我的音频添加效果函数

   private fund addEffetToAudioFile(pitch: Float, rate: Float, reverb: Float, echo: Float) { // Initialize variables
audioEngine = AVAudioEngine()
audioPlayerNode = AVAudioPlayerNode()
audioEngine.attachNode(audioPlayerNode)

// Setting the pitch
let pitchEffect = AVAudioUnitTimePitch()
pitchEffect.pitch = pitch
audioEngine.attachNode(pitchEffect)

// Setting the platback-rate
let playbackRateEffect = AVAudioUnitVarispeed()
playbackRateEffect.rate = rate
audioEngine.attachNode(playbackRateEffect)

// Setting the reverb effect
let reverbEffect = AVAudioUnitReverb()
reverbEffect.loadFactoryPreset(AVAudioUnitReverbPreset.Cathedral)
reverbEffect.wetDryMix = reverb
audioEngine.attachNode(reverbEffect)

// Setting the echo effect on a specific interval
let echoEffect = AVAudioUnitDelay()
echoEffect.delayTime = NSTimeInterval(echo)
audioEngine.attachNode(echoEffect)

// Chain all these up, ending with the output
audioEngine.connect(audioPlayerNode, to: playbackRateEffect, format: nil)
audioEngine.connect(playbackRateEffect, to: pitchEffect, format: nil)
audioEngine.connect(pitchEffect, to: reverbEffect, format: nil)
audioEngine.connect(reverbEffect, to: echoEffect, format: nil)
audioEngine.connect(echoEffect, to: audioEngine.mainMixerNode, format: nil)

// Good practice to stop before starting
audioPlayerNode.stop()

// Play the audio file
if (audioEngine != nil) {
audioEngine?.stop()
}

do {
audioFile = try AVAudioFile(forReading: self.recordedAudioURL)
} catch {
print("Error: Can't create audio file")
self.showAlert(TYSAudioEditorHelper.Alerts.AudioFileError, message: String(error))
return
}

audioPlayerNode.scheduleFile(audioFile, atTime: nil, completionHandler: {
print("Complete")
})

try! audioEngine.start()

let dirPaths: AnyObject = NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0]
let tmpFileUrl: NSURL = NSURL.fileURLWithPath(dirPaths.stringByAppendingPathComponent(kOutputSoundWithEffectFileName))
do {
self.newAudio = try AVAudioFile(forWriting: tmpFileUrl, settings:[
AVFormatIDKey: NSNumber(unsignedInt:kAudioFormatMPEG4AAC_HE),
AVEncoderAudioQualityKey : AVAudioQuality.Medium.rawValue,
AVEncoderBitRateKey : 12800,
AVNumberOfChannelsKey: 2,
AVSampleRateKey : 44100.0
])

/*Error in this line*/ audioEngine.mainMixerNode.installTapOnBus(0, bufferSize: 2048, format: audioEngine.mainMixerNode.inputFormatForBus(1)) { (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
print(self.newAudio.length)
if (self.newAudio.length) < (self.audioFile.length) {
//Let us know when to stop saving the file, otherwise saving infinitely
do {
try self.newAudio.writeFromBuffer(buffer)
} catch {
print("Problem Writing Buffer")
}
} else {
self.audioEngine.mainMixerNode.removeTapOnBus(0)
//if we dont remove it, will keep on tapping infinitely
self.newAudio = nil
if (self.audioEngine != nil) {
self.audioEngine?.stop()
}
self.removeOldFileIfExist(self.kOriginalVideoSoundFileName)
self.saveAudioFileInVideo(tmpFileUrl)
}
}
} catch {
print("Problem")
}

do {
try audioEngine.start()
} catch {
showAlert(TYSAudioEditorHelper.Alerts.AudioEngineError, message: String(error))
return
}

// play the recording!
audioPlayerNode.play()
}

最佳答案

根据 https://developer.apple.com/reference/audiotoolbox/1584138-anonymous/kaudiouniterr_propertynotwritable?language=objc那个错误是

kAudioUnitErr_PropertyNotWritable = -10865

根据 https://developer.apple.com/reference/avfoundation/avaudionode/1387122-installtap

format: If non-nil, attempts to apply this as the format of the specified output bus. This should only be done when attaching to an output bus which is not connected to another node; an error will result otherwise. The tap and connection formats (if non-nil) on the specified bus should be identical. Otherwise, the latter operation will override any previously set format. For AVAudioOutputNode, tap format must be specified as nil.

所以可能是以下之一:

  1. mainMixerNode 已经连接到另一个节点,所以你需要在安装 tap 之前断开它们

  2. mainMixerNode是一个AVAudioOutputNode,所以这个参数需要传入nil

关于swift - 音频引擎仅在运行 iOS 10 的设备(iphone 6s)上失败,在所有模拟器设备或真实设备上运行良好,直到 iphone 6s,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39614193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com