2015-12-17 20 views
5

Tôi có ghi lại một số bằng giọng nói vào tài liệu thư mục sử dụng phương pháp sau đâyLàm thế nào để chuyển đổi tệp .caf thành tệp .mp3?

func record() { 
    self.prepareToRecord() 
    if let recorder = self.audioRecorder { 
     recorder.record() 
    } 
} 

    let recordSettings = [ 
    AVSampleRateKey : NSNumber(float: Float(44100.0)), 
    AVFormatIDKey : NSNumber(int: Int32(kAudioFormatAppleLossless)), 
    AVNumberOfChannelsKey : NSNumber(int: 2), 
    AVEncoderAudioQualityKey : NSNumber(int: Int32(AVAudioQuality.Medium.rawValue)), 
    AVEncoderBitRateKey : NSNumber(int: Int32(320000)) 
] 

    func prepareToRecord() { 

    let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString 
    let soundFileURL: NSURL? = NSURL.fileURLWithPath("\(documentsPath)/recording.caf") 
    print("\(soundFileURL)") 

    self.audioRecorder = try! AVAudioRecorder(URL: soundFileURL!, settings: recordSettings) 

    if let recorder = self.audioRecorder { 
     recorder.prepareToRecord() 
    } 
} 

Phương pháp này sẽ lưu các tập tin âm thanh như recording.caf trong vào danh mục tài liệu, nhưng tôi muốn chuyển đổi tập tin recording.caf này trong sang mp3 để thao tác thêm.

Cách chuyển đổi tệp .caf này thành .mp3 nhanh chóng?

+0

apple không hỗ trợ mp3, tại sao bạn không lưu nó thành .mp4? – karthikeyan

Trả lời

4

mp3 codec không được hỗ trợ bởi AVAudioRecorder vì của hoàng Danh sách các codec có sẵn:

kAudioFormatMPEG4AAC
kAudioFormatAppleLossless
kAudioFormatAppleIMA4
kAudioFormatiLBC
kAudioFormatULaw
kAudioFormatLinearPCM

Bạn có thể tìm thấy những thông tin chi tiết tại đây How do I record audio on iPhone with AVAudioRecorder?

Các vấn đề liên quan