I'd like to be able to play back audio I've recorded using AVAudioRecorder @ 1.5x or 2.0x speed. I don't see anything in AVAudioPlayer that will support that. I'd appreciate some suggestions, with code if possible, on how to accomplish this with the iPhone 3.x SDK. I'm not overly concerned with lowering the pitch to compensate for increased playback speed, but being able to do so would be optimal.
3 Answers
Changing the sample rate should work just like a tape recorder would if you played it faster. Everything becomes higher in pitch. To keep the pitch the same, you would need to set up an Audio Unit graph that includes the AUPitch effect, and lower the pitch by the same ratio that you increase the sample rate by.

- 8,665
- 3
- 34
- 41
See this question. In other words, you'll have to use a different API like Audio Queue Services. If you want to try a simple hack, you can try doubling the sample rate property of the audio file. It probably won't work though. Also, be warned that it is fairly CPU demanding to adjust the playback speed while keeping the same pitch. You'll need to use a one of the available techniques called "time stretching". Also, in case you haven't realized it by now, doing complicated things with audio on the iPhone is a major pain because Apple's documentation is generally either very bad or nonexistent.

- 1
- 1

- 46,722
- 6
- 58
- 80
-
So, if I am recording at a sample rate of 8000, then theoretically changing the sample rate to 12000 for playback should result in 1.5x speed? – memmons Mar 22 '10 at 05:38
-
Yes, if it will take arbitrary sample rates rather than just the common ones (44100, 22050, etc.). I think that it will, but I haven't tried it. – Justin Peel Mar 22 '10 at 15:12
-
I'll give it a try and post the results today. – memmons Mar 25 '10 at 16:11
If you want to play audio faster or slower, there is a build-in method in avAudioPlayer. Have you tried AudioPlayer Rate property ? in Swift it will be like this -
audioP = try! AVAudioPlayer(contentsOf: URL(fileURLWithPath: selectedPath), fileTypeHint: "caf")
audioP.enableRate = true
audioP.prepareToPlay()
audioP.rate = 1.5
audioP.play()

- 200
- 3
- 9