How to Alter the Speed of an Audio File in Swift

Assuming you figured how to play an audio file in Swift, now you want to play with the speed of the audio. The rate property of the AVAudioPlayer object is what you need to change up the speed. The catch is that you need to set the enableRate property to true before you can actually do this.

Screen Shot 2016-02-02 at 5.25.11 PM.png

In this example I create a helper function to set things up. audioPlayer is my instance of AVAudioPlayerI set currentTime in my use case to start the audio from the beginning. It is also a good practice to stop the audio before playing.

Screen Shot 2016-02-02 at 5.18.17 PM.png

Then I call that function in my actions

Screen Shot 2016-02-02 at 5.18.29 PM.png

That’s it mainly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: