kodeco.com Forums

AVAudioEngine Tutorial for iOS: Getting Started

In this AVAudioEngine tutorial, you'll learn how to add advanced audio functionality using Apple's higher-level audio toolkit.

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5154-avaudioengine-tutorial-for-ios-getting-started

Getting choppy sound when changing rate of audio file.
Is their any way to maintain same quality while changing the rate.

@scott4arrows Can you please help with this when you get a chance? Thank you - much appreciated! :]

@kksuthar321 apologies for not getting back to you sooner. I compared rate changing in an “official” podcast app vs the sample project. I did not notice much of a difference in quality between the two.

The rate in the sample project is controlled by an AVAudioUnitTimePitch object which is provided by AVFoundation, so we don’t have any control of how rate change is implemented in that class.

However, if you are noticing a substantial sound quality issue, can you record a screencast of your build and post a link to it for me to view.


I would like to use this to play audiobooks but it seems not able to do so with out some major modification.

Can you offer suggestions that would help in making this app play audiobooks?


@scott4arrows Do you have any feedback regarding this? Thank you - much appreciated! :]


Can you give me any more details?

There are 2 possible issues that I can think of:

  1. Unsupported file format - here is a list of most supported (can’t confirm this is all of the supported codecs):
    • AAC (M4A, M4B, M4P)
    • MP3
    • WAV
    • AA (audible.com spoken word, formats 2, 3, and 4)
    • AIFF
  2. If you are using one of the file formats listed above, then the File URL might not be loading properly. In ViewController.swift in the project, check that this line audioFileURL = Bundle.main.url(forResource: "Intro", withExtension: "mp4") is creating the audioFileURL.

The way the sample app is setup, it expects the audio file to be in the app bundle. Check that your audiobook file is being copied into your app bundle in “Copy Bundle Resources” section of Build Phases.

Let me know if these suggestions do not work for you.


Here is the line of code that works

audioFileURL = Bundle.main.url(forResource: “Saints”, withExtension: “mp3”)

Here is the line of code that will not work.

audioFileURL = Bundle.main.url(forResource: “Saints”, withExtension: “m4b”)

This is the line of code that causes to program to abort

210 var secs = Int(ceil(time)) ----- the time is bad
so I changed added this line just before
lat time = 10.56 to force a value into time

Then tried again using Saints.mp3 and it worked
Then tried again using Saints.m4b and no audio played.

Hope this helps as I have been trying to get a project of mine to play a m4b audiobook with no success. I was hoping I could find a what I was doing wrong.



I was able to add a m4b and play it.

Check to see that after you added Saints.m4b to your project that it also was added to the Copy Bundle Resources section.

If not, just click the + button underneath and add it.

If that is set and still doesn’t, just to confirm that your m4b file is playable, try using iTunes app or QuickTime Player to play it.



Thanks very much that fixed it. I did not realize that I needed to Copy Bundle Resources. I just dragged and dropped the m4b to the project the same way I did the mp3 files.

By the way your audio project is great i love it. My project is being created for those who have low vision and also have problems comprehending how to operate a iPad or iPhone.


Excellent!! I had the same issue when I added the m4b file. My guess is that Xcode will do it for files it recognizes as resources.

Thanks. Keep me posted on your app. I’d like to check it out when you’ve completed.



I will be glad to let you check it out when I have completed it.

This is my first app of any complexity and I am 80 years old this year so I may never get it finished. Sometimes I get stuck and spend weeks trying to figure something out. But it keeps me going and my brain active. My wife is the one who inspired me to try this because she has low vision and likes to listen to books but most all of the book readers we tried had too many small buttons and too much complexity for her to figure out. We tried voice over but that really confuse her. We did find a reader for android called Homer which works pretty good for her but she now has 2 tablets to work with because she uses the iPad for FaceTime with the grandkids.

But again thanks for your help.

1 Like

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!