How to generate heartbeat sounds in Python given beats per minute?

Question:

I’m looking to pass in an integer beats per minute (bpm) variable value (e.g. 62) into a function in Python that outputs the accompanying heartbeat noises (i.e. 62 heart beat sounds in a minute).

I can’t find any libraries that can help with this and Google searching leads me to only find the reverse (i.e. calculating bpm given heartbeat audio file).

How would I go about achieving this?

I was thinking of downloading an MP3 heartbeat sound and somehow manipulating that based on the number of bpm, but not sure this will work.

Asked By: Ricardo Francois

||

Answers:

You can use time.sleep() and divide 60 by bpm, than something to play an audio file. For example.

import time
from playsound import playsound

bpm=int(input("how many beats per a minute?: "))
delay=60/bpm

while True:
    playsound('/path/sound.wav')
    time.sleep(delay)
Answered By: knight4him