let pitchshifter = AKPitchShifter(self.audioPlayer)pitchshifter.shift = 10AudioKit.output = pitchshifter
如果我在应用程序中播放它,它可以工作,但我想将其保存为新文件,以便稍后将其用作avasset.如何实施?
我尝试使用AKNodeRecorder,但这会产生空音轨:
let url = fileManager.default.urls(for: .documentDirectory,in: .userDomainMask).first!.appendingPathComponent("recorded")let format = AVAudioFormat(commonFormat: .pcmFormatfloat64,sampleRate: 44100,channels: 2,interleaved: false)!let tape = try! AKAudiofile(forWriting: url,settings: format.settings)let mixer = AKmixer(self.audioPlayer!,pitchshifter)AudioKit.output = mixerself.recorder = try! AKNodeRecorder(node: mixer,file: tape)try? AudioKit.start()self.audioPlayer?.play()self.audioPlayer?.completionHandler = { self.recorder?.stop() self.selectedAudioURL = tape.url}
我也尝试了renderTofile方法 – 它也没有工作and I got this error
let url = fileManager.default.urls(for: .documentDirectory,in: .userDomainMask).first!.appendingPathComponent("recorded.m4a")let format = AVAudioFormat(commonFormat: .pcmFormatfloat64,settings: format.settings)try! AudioKit.renderTofile(tape,seconds: Double(CMTimeGetSeconds(self.selectedAudioAsset!.duration)))
这就是我将初始文件添加到AudioKit的方法:
let audiofile = try AKAudiofile(forReading: audioURL,commonFormat: .pcmFormatfloat32,interleaved: true)let player = AKPlayer(audiofile: audiofile)self.audiofile = audiofileself.audioPlayer = playerplayer.startTime = self.startTimeAKSettings.defaultToSpeaker = true
在此先感谢您的回答!
解决方法 根据我的发现,您必须使用预渲染器来“播放”您想要录制的内容:try AudioKit.renderTofile(outputfileForWriting,duration: sequencerTotalSeconds,prerender: { self.sequencer.play()})
但是,对我来说.渲染单个轨道序列会产生窦音. : – /
希望这可以帮助!
总结以上是内存溢出为你收集整理的ios – 如何使用AudioKit保存音频文件?全部内容,希望文章能够帮你解决ios – 如何使用AudioKit保存音频文件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)