OC

Knowledge OS
登录 注册
全部话题 移民 创业 iOS Mac Objective-C Swift Android 招聘 求职

如何用Swift录音

tinyfool
tinyfool 发布于 2016年01月10日
无人欣赏。
class Recorder {
 var audioRecorder:AVAudioRecorder!
 func record(){
 let audioSession:AVAudioSession = AVAudioSession.sharedInstance()
 try! audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
 try! audioSession.setActive(true)
 let documents: AnyObject = NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0]
 let str = documents.stringByAppendingPathComponent("recordTest.caf")
 let url = NSURL.fileURLWithPath(str as String)
 let recordSettings:[String : AnyObject] = [AVFormatIDKey:NSNumber(unsignedInt:kAudioFormatAppleIMA4),
 AVSampleRateKey:44100.0,
 AVNumberOfChannelsKey:2,AVEncoderBitRateKey:12800,
 AVLinearPCMBitDepthKey:16,
 AVEncoderAudioQualityKey:AVAudioQuality.Max.rawValue]
 print("url : (url)")
 try! audioRecorder = AVAudioRecorder(URL:url, settings: recordSettings)
 audioRecorder.record()
 }
}
共1条回复
楼长 ·
chenyf 回复于 2016年01月10日

pretty cool!

登录 或者 注册

AltStyle によって変換されたページ (->オリジナル) /