theDuncs theDuncs - 1 month ago 19
Objective-C Question

Play a sound for a specific period of time

I have a heart-rate monitor, and a short wav file which sounds like a heart beating. This wav file has a duration of 1 second.

I want to play it in time with the user's heart rate. So if their heart rate is 100bpm, the sound should play for 0.6 seconds. If their heart rate is 60bpm, the sound should play for 1.0 seconds. And if their heart rate is 30bpm they are probably about to die.

Is it possible to alter the duration of time it takes to play a sound file? And what framework should I use? AVPlayer?

Answer

check this one: How can I use AVAudioPlayer to play audio faster *and* higher pitched?

It says you can change the .rate property of an AVAudioPlayer to play it faster.

ps: it won't change the pitch of the sound. If you also need this, check the question I mentioned.