7

I have built an iOS App in Swift that records audio clips, these clips are then sent up to the server. Every recording I make is very quiet.

Initially I thought my problems were similar to this question on Stack Overflow - but after trying this solution, my recordings are still very quiet.

Routing the audio through the speaker does not make the recordings any louder, as is suggested here:

https://stackoverflow.com/a/5662478/1037617

Note that its not playback on the device that is an issue. The issue is that the recordings are too quiet. I have tested the Microphone itself, and it is fine.

This is the best waveform I can produce, and this is almost shouting into the Microphone. As you can see, the waveform recorded is very quiet:

This is the best waveform I can produce, and this is almost shouting into the Microphone. As you can see, the waveform recorded is very quiet.

Is there any way of getting my iOS App to record at a louder volume?

This is the code I am using to record the audio clips:

let recorderSettings=[
    AVFormatIDKey            : kAudioFormatLinearPCM,
    AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue,
    AVEncoderBitRateKey      : 128000,
    AVNumberOfChannelsKey    : 1,
    AVSampleRateKey          : 44100.0
]

let session: AVAudioSession = AVAudioSession.sharedInstance()
var error: NSError?
if session.respondsToSelector("requestRecordPermission:") {
    AVAudioSession.sharedInstance().requestRecordPermission( { (granted:Bool) -> Void in
        if !granted {
            println("permission not granted")
        }else{
            println("permission granted")

            if !session.setCategory(AVAudioSessionCategoryRecord, error: &error) { // also tried PlaybackAndRecord
                println("could not set sesssion category")
                if let e = error {
                    println(e.localizedDescription)
                }
            }

            if !session.overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker, error: &error) {
                println("could not override output audio")
                if let e = error {
                    println(e.localizedDescription)
                }
            }

            if !session.setActive(true, error: &error) {
                println("could not make active")
                if let e = error {
                    println(e.localizedDescription)
                }
            }

            self.currentFilename = "xxxx.wav"
            let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
            let docsDir: AnyObject=dirPaths[0]
            self.recordedFilePath = docsDir.stringByAppendingPathComponent(self.currentFilename)
            self.recordedFileURL = NSURL(fileURLWithPath: self.recordedFilePath)

            self.recorder = AVAudioRecorder(URL:self.recordedFileURL, settings: self.recorderSettings, error: &error)

            if let e = error {
                println(e)
                println(e.localizedDescription)
                var err = NSError(domain: NSOSStatusErrorDomain, code: e.code, userInfo: nil)
                println(err.description)
            }else{

                self.recorder?.delegate = self
                self.recorder?.meteringEnabled = true
                self.recorder?.prepareToRecord()

                self.recorder?.record()

                self.meterTimer = NSTimer.scheduledTimerWithTimeInterval(0.1,
                    target: self,
                    selector: "updateRecordAudioMeter:",
                    userInfo: nil,
                    repeats: true)

            }
        }
    })
}
Community
  • 1
  • 1
Jimmery
  • 9,783
  • 25
  • 83
  • 157
  • Can I see your recorderSettings? Also have you tried this code on different devices ? Maybe your device mic is broken – Zell B. Jan 21 '15 at 16:20
  • @zellb Ive added the recorderSettings. The problem definitely isnt the mic - Ive tried and tested a few already. – Jimmery Jan 22 '15 at 08:58
  • 11
    any update/solution on this? I am experiencing something similar? – James Gilchrist Mar 08 '15 at 16:36
  • 1
    I'm curious to know a better solution for this as well. I've tried the answers given below however the recording volume is still pretty low. I'm comparing it to Voice Memos app (default iOS app for recording) and it somehow records or plays back the recording louder. I would like to achieve the same thing. – C0D3 Oct 01 '20 at 01:25

2 Answers2

7

When recording audio, set the audio session to AVAudioSessionCategoryPlayAndRecord or just AVAudioSessionCategoryRecord. When you're done, set it back to just AVAudioSessionCategoryPlayback.

icaksama
  • 712
  • 10
  • 15
3

You need to set the AVAudioSession category back to AVAudioSessionCategoryPlayback after recording

Roland Keesom
  • 8,180
  • 5
  • 45
  • 52