pro100andrey / lame

Swift Lame Framework
MIT License
35 stars 7 forks source link

mp3 file full with noise #7

Closed Abir-crypto closed 2 years ago

Abir-crypto commented 2 years ago

Hey after I convert the file from m4a to mp3, the file is only noise. Can't hear anything else. I've just copied everything from the example project as it is.

pro100andrey commented 2 years ago

Hi @Abir-crypto, AudioConverter.swift this pcm to mp3 coveter.

You are not decoding the M4A audio into raw audio data before sending it into LAME.

"PCM audio" means no compression.

Thanks!

pro100andrey commented 2 years ago

@Abir-crypto Example how to record wav file

 let fileURL: URL = {
            let src = "sound.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)")
        }