hemant
hemant

Reputation: 1843

Recording WAV format file with AVAudioRecorder?

I am trying to record an wav file with AVAudiorecorder using the following settings. The file created plays fine on my mac and iPhone but when i mail it to a blackberry device and try to play it from there it says the format is not supported.. what am i possibly doing wrong?? i believe i am missing something when initializing the settings for the audiorecorder so i am posting only the settings dictionary

NSDictionary *settings = [[NSDictionary alloc] initWithObjectsAndKeys:
                                 [NSNumber numberWithFloat: 44100.0],AVSampleRateKey,
                                 [NSNumber numberWithInt: kAudioFormatLinearPCM],AVFormatIDKey,// kAudioFormatLinearPCM
                                 [NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
                                 [NSNumber numberWithInt: 2], AVNumberOfChannelsKey,
                                 [NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
                                 [NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,  
                                 [NSNumber numberWithInt: AVAudioQualityMedium],AVEncoderAudioQualityKey,nil];

Upvotes: 3

Views: 6449

Answers (1)

black_pearl
black_pearl

Reputation: 2719

mush easier to achieve this, in 2021 with swift 5,

      let fileURL: URL = {
            let src = "abc.wav"
            return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent(src)
       }()


       let recordSettings: [String : Any] = [AVFormatIDKey: Int(kAudioFormatLinearPCM),
                                      AVSampleRateKey: 44100.0,
                                      AVNumberOfChannelsKey: 1,
                                      AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue ]
        
        do {
            audioRecorder = try AVAudioRecorder(url: fileURL, settings: recordSettings)
            audioRecorder?.prepareToRecord()
        } catch {
            print("Error creating audio Recorder. \(error)")
        }
    

Upvotes: 3

Related Questions