Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recorder is not recording clear audio #164

Closed
RizwanaDesai opened this issue Aug 5, 2024 · 9 comments
Closed

Recorder is not recording clear audio #164

RizwanaDesai opened this issue Aug 5, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@RizwanaDesai
Copy link

macOS Version(s) Used to Build

macOS 13 Ventura

Xcode Version(s)

Xcode 14

Description

Recorder is not recording clear audio,

We are using AudioKit in our app and from iOS 18 we are facing difficulty with audio quality, tried out Recorder in this demo app too, and demo has the same issue with audio quality.

Crash Logs, Screenshots or Other Attachments (if applicable)

Steps to reproduce in Demo App:

  • Click on Mini Apps
  • Click on Recorder
  • Record Audio
  • And Play that audio, audio sound would not be clear in that.

MacOS:14.2
Xcode: 15.1
Issue reproducible in iOS18 beta

@RizwanaDesai RizwanaDesai added the bug Something isn't working label Aug 5, 2024
@NickCulbertson
Copy link
Member

This was mentioned on the AudioKit Discord. I don't think there is an official solution yet, but @Matt54 said Adding Settings.sampleRate = 48_000 during my audio session config fixed it.

@RizwanaDesai
Copy link
Author

Yeah, I was about to try the same, as when i tried directly with audio engine it worked with 48000 sample Rate.
Thanks @NickCulbertson!

@RizwanaDesai
Copy link
Author

Adding Settings.sampleRate = 48_000 resolves the issue; however, the first recording attempt results in a blank audio file. After navigating back to Mini Apps and attempting to record again, it consistently works from the second attempt onward. @NickCulbertson

@NickCulbertson
Copy link
Member

Thanks for the info. I'll download the beta this week or next to see what is going on. One thing to note is that if I add Settings.sampleRate = 48_000 in my current version of the macOS/iOS using Xcode 15 it creates pops. So I would check for backwards compatibility. There might be some way to check the sample rate of the input node directly, but I have not had a chance to try that yet.

I was not able to recreate the issue of the first recording not working. That might have to do with where you are calling Settings.sampleRate = 48_000.

@RizwanaDesai
Copy link
Author

RizwanaDesai commented Sep 3, 2024

You can check the sample rate for the inputNode with this code:
engine.avEngine.inputNode.inputFormat(forBus: 0).sampleRate
I think I saw a static sample rate of 44100 Hz in AudioKit before, but I'm not completely sure. This might be causing the issue if there's a difference in sample rates.

And I have setup sampleRate in init() in Demo Project.
Screenshot 2024-09-03 at 6 57 34 PM

@RizwanaDesai
Copy link
Author

nvm fixed it. Will have to configure setting before audio engine initialize

@NickCulbertson
Copy link
Member

NickCulbertson commented Sep 3, 2024

Actually it looks like this might work In CookbookApp:

init() {
        #if os(iOS)
            do {
                Settings.bufferLength = .short
                if #available(iOS 18.0, *) {
                    if !ProcessInfo.processInfo.isMacCatalystApp && !ProcessInfo.processInfo.isiOSAppOnMac {
                        // iOS 18 app (not on Mac)
                        Settings.sampleRate = 48_000
                    }
                }

                try AVAudioSession.sharedInstance().setPreferredIOBufferDuration(Settings.bufferLength.duration)
                try AVAudioSession.sharedInstance().setCategory(.playAndRecord,
                                                                options: [.defaultToSpeaker, .mixWithOthers, .allowBluetoothA2DP])
                try AVAudioSession.sharedInstance().setActive(true)
            } catch let err {
                print(err)
            }
        #endif
    }

@NickCulbertson
Copy link
Member

Thanks for the heads up! This is now fixed here: #165

@NickCulbertson
Copy link
Member

NickCulbertson commented Oct 11, 2024

Small update from #167

if #available(iOS 18.0, *) {
    if !ProcessInfo.processInfo.isMacCatalystApp && !ProcessInfo.processInfo.isiOSAppOnMac {
        // iOS 18 app (not on Mac)
        Settings.sampleRate = 48_000
    }
}

This seems to work better than setting it to AVAudioSession's sampleRate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants