Hello,
I run the original example of RecorderDemo and It compiles with only one error for exportAsynchronously:
Export Failed Optional(Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12936), NSLocalizedDescription=The operation could not be completed, NSURL=/Users/miguelsaldana/Library/Developer/CoreSimulator/Devices/79E361A8-8DA9-4E2B-8264-0ED34E1EFCB7/data/Containers/Data/Application/BD8F35B0-2A75-4046-95CC-BF30709C52D3/tmp/DBAE1838-D059-422D-B66B-23454350F109.caf, NSUnderlyingError=0x60000024ebe0 {Error Domain=NSOSStatusErrorDomain Code=-12936 "(null)"}})
anyone got a solution?
It does work with .wav to m4a but I want to convert .caf to .m4a :)
Thank you
I don't have a solution, but thanks for making the issue. Will keep it open until it can be addressed.
I have this too, in my own project and in that example. I can't seem to record and export, which is a pretty fundamental problem. Any workarounds until this is fixed?
I used AVAssetExportSession and make my own converter.
its easy couple lines.
@masaldana2 Care to share your code?
yes, im sorry im still a noob getting around github
here
`
func convertAudiotoM4A(name:String, cafURL: URL) -> URL{
let url = NSURL.fileURL(withPath: cafURL.absoluteString)
let audioURL = AVURLAsset(url: url)
let exported = AVAssetExportSession(asset: audioURL, presetName: AVAssetExportPresetAppleM4A)
exported?.outputFileType = AVFileTypeAppleM4A
let cacheDir = NSTemporaryDirectory()
let filePath:String = cacheDir + name + ".m4a"
print(filePath)
//delete prev recording m4a if there's already one
let fileManager = FileManager.default
do{
try? fileManager.removeItem(atPath: filePath)
}catch{
print("couldnt delete old caf")
}
exported?.outputURL = NSURL(fileURLWithPath: filePath) as URL
exported?.exportAsynchronously(completionHandler: {
if exported?.error != nil{
print(exported?.error)
}else{
print("success creating m4a")
}
})
return NSURL(fileURLWithPath: filePath) as URL
}
`
I still get the same error after adding some code similar to that. It must be something wrong with the input in some way...
i did this before calling the func
`
var fileURL:URL = (self.conductor.recorder.audioFile?.url)!
//rename file http://www.techotopia.com/index.php/Working_with_Files_in_Swift_on_iOS_8
let filemgr = FileManager.default
var fileNewURL = String(describing: fileURL.deletingLastPathComponent()).appending((recordingName?.text)! + ".caf")
//clear prev file
let fileManager = FileManager.default
do{
try? fileManager.removeItem(atPath: fileNewURL)
}catch{
print("couldnt delete old caf")
}
do {
try filemgr.copyItem(atPath: fileURL.absoluteString, toPath: fileNewURL)
print("Copy successful")
} catch let error {
print("Error: \(error.localizedDescription)")
`
That looks like it's just copying the file, which I don't think would help with this error. I'm wondering if there's something wrong with the way the .caf file is created @aure
@aure, the usual export function appears to work fine with doing the following to create the audio file (with a .caf extension):
let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 44100, channels: 2, interleaved: false)
let audioFile = try AKAudioFile(forWriting: recordingUrl, settings: format.settings)
None of the copying or using AVAssetExportSession directly is needed in that case. Although I appear to have no effects in my recording, but I suspect that's a different problem.
I had the same issue as @masaldana2 above. Typical non-helpful error message from AVFoundation, specifically the -12936 code.
His solution is correct also. Line 390 of AKAudioFile+ProcessingAsynchronously.swift:
internalExportSession.outputURL = URL(fileURLWithPath: filePath)
should probably be replaced with
internalExportSession.outputURL = NSURL(fileURLWithPath: filePath) as URL
This issue is reproducible In the Recorder demo. This export call below will generate the error with -12396 code:
player?.audioFile.exportAsynchronously(name: "TempTestFile.m4a", baseDir: .documents, exportFormat: .m4a) {_, error in
if error != nil {
print("Export Failed \(error)")
} else {
print("Export succeeded")
}
This can be fixed without modifying the AudioKit code directly by calling the function @masaldana2 designed above. See attached file.
@CharlesSieg Line 390 is correct in Swift 3. The NS has been dropped (e.g. you have FileManager not NSFileManager in your code)
Yeah that code looks like it should work. I did something similar and got a different error, but I'll try again at some point. For now it's recording fine anyway with my other change, but I'm stuck with #749.
For me the code didn't work in the recorder example and I got the same error, but I just replaced it with this......... Mozel Tov!
let fileName = player?.audioFile.url.lastPathComponent
do {
let nonExistentFile = try AKAudioFile(readFileName: fileName!,
baseDir: .temp)
try nonExistentFile.exportAsynchronously(name: "exported.m4a", baseDir: .documents, exportFormat: .m4a) { exportedFile, error in
print("myExportCallBack has been triggered. It means that export ended")
if error == nil {
print("Export succeeded")
}
else {
print("Export failed\(error)")
}
}
} catch let error as NSError {
print("There's an error: \(error)")
}
So, a lot has been said on this thread and it seems like the original poster and a few others are satisfied. Should this be closed? Anything that should change in AudioKit as a result of this?
I think one of the solutions does need building in to AudioKit. The sample project for recording from the microphone doesn't work as is.
Who wants to be a hero and make a pull request? I can even do a screen share with whoever if its your first time making a pull request.
@aure There you go, hopefully that'll be ok
Still seeing this issue.
Most helpful comment
I don't have a solution, but thanks for making the issue. Will keep it open until it can be addressed.