AudioKit: AKOfflineRenderNode doesn't render any sound.
I utilized AKOfflineRenderNode to process recorded voice. The idea is to record voice and save it into the file. Next apply some effects to this file and save combined voice+effects into file.
I have successful result on my iPhone 6s running on iOS 11.0.3 but on other devices running on iOS 11+(for example last generation of iPad on 11.0.3) I always have “silent” file with same size about 60 Kb. I attached one for reference(rec.zip). Also the issue 100% reproducible on iOS 11 simulator.
Here is my setup(I removed effects setup since offline render doesn’t work even on clean recording):
fileprivate func setupAudioKit(){
AKSettings.enableLogging = true
AKAudioFile.cleanTempDirectory()
AKSettings.bufferLength = .medium
AKSettings.numberOfChannels = 2
AKSettings.sampleRate = 44100
AKSettings.defaultToSpeaker = true
do {
try AKSettings.setSession(category: .playAndRecord, with: .allowBluetoothA2DP)
} catch {
AKLog("Could not set session category")
}
mic = AKMicrophone()
micMixer = AKMixer(mic)
recorder = try? AKNodeRecorder(node: micMixer)
if let file = recorder.audioFile {
player = try? AKAudioPlayer(file: file)
player.looping = true
}
playerMixer = AKMixer(player)
// Effects setup
offlineRenderer = AKOfflineRenderNode(playerMixer)
AudioKit.output = offlineRenderer
AudioKit.start()
}
Here is export method:
fileprivate func render() {
offlineRenderer.internalRenderEnabled = false
player.schedule(from: 0, to: player.duration, avTime: nil)
let renderURL = URL(fileURLWithPath: FileHelper.documentsDirectory() + "rec.m4a")
let sampleTimeZero = AVAudioTime(sampleTime: 0, atRate: AudioKit.format.sampleRate)
player.play(at: sampleTimeZero)
do {
try offlineRenderer.renderToURL(renderURL, seconds: player.duration)
} catch {
print(error)
}
player.stop()
offlineRenderer.internalRenderEnabled = true
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 30 (14 by maintainers)
Except the share part, this is what RecorderDemo does.
No, you can’t right now but we’re working on it!
I’m curious; do you know if this would work with playback from AKSequencer (i.e., MIDI)?
@eljeff I’m with you on this. It’s a bit of work though. Currently AudioKit uses a global AVAudioEngine, I believe that we will need to make all audiokit functions pass around an audioEngine if we want to achieve this. We could default to a global engine if audioEngine argument is missing. I also think that it’s totally worth it to do this. Not only will we have more control over offline rendering; we would also gain the ability to let AudioKit act as a “slave” engine. For my projects it’s worth it to bounce tracks without stopping playback. I have some thoughts on how to do this, I’d love to hear yours.
Ok I’ve got a working offline render function implemented as AudioKit.renderToFile, and I’ve deprecated AKOfflineRenderNode. Thanks for finding this.
https://github.com/AudioKit/AudioKit/pull/1114