当您使用AVAudioRecorder 录制音频时,您必须将路径传递为您存储音频的位置的url。因此,默认情况下它将音频存储在该位置。
例如,
var audioSession:AVAudioSession = AVAudioSession.sharedInstance()
audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
audioSession.setActive(true, error: nil)
var documents: AnyObject = NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0]
var str = documents.stringByAppendingPathComponent("myRecording1.caf")
var url = NSURL.fileURLWithPath(str as String)
var recordSettings = [AVFormatIDKey:kAudioFormatAppleIMA4,
AVSampleRateKey:44100.0,
AVNumberOfChannelsKey:2,AVEncoderBitRateKey:12800,
AVLinearPCMBitDepthKey:16,
AVEncoderAudioQualityKey:AVAudioQuality.Max.rawValue
]
println("url : \(url)")
var error: NSError?
audioRecorder = AVAudioRecorder(URL:url, settings: recordSettings, error: &error)
if let e = error {
println(e.localizedDescription)
} else {
audioRecorder.record()
}
因此,url 是存储音频的位置,您可以使用相同的url 播放该音频。如果你想将它发送到服务器,你可以从 url 或路径中获取该文件 data。
因此,如果您使用的是第三方库,请检查它存储音频的位置,您可以从那里获取它,或者它应该有一些方法来获取它的位置。
PS:不需要使用第三方库来录制音频,因为您可以通过AVAudioRecorder 和AVAudioPlayer 轻松管理它(用于从 url 播放音频)。
简而言之,如果您正在录制音频,那么您肯定也可以并行存储它!
您可以参考Ravi shankar's tutorial also
参考:this so post