【发布时间】:2016-09-21 10:37:21
【问题描述】:
我确实尝试将效果添加到音频文件,它确实适用于 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()
}
【问题讨论】:
标签: swift avfoundation avaudioplayer core-audio ios10