Skip to content

Commit

Permalink
Update sound_detector.py by adding comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabrielparizet committed Apr 3, 2023
1 parent c54db69 commit e5bf73e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions api/sound_detector.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Importing librosa.
import librosa

# find_tempo takes an audio file as argument and returns a formatted string that indicates the tempo of that audio file.
def find_tempo(filename):
# librosa.load is used to load the audio file into memory as a waveform and a sample rate.
y, sr = librosa.load(filename)
# librosa.beat.beat_track is used to calculate the tempo of the audio file based on its beat frames, which are stored in beat_frames.
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)
file_tempo = format_tempo(tempo)
return f'Your audio file tempo is of {file_tempo} bpm.'


# format_tempo takes a floating-point number and returns a string representation of that number with two decimal places.
def format_tempo(float):
float = "{:.2f}".format(float)
return float
return float


0 comments on commit e5bf73e

Please sign in to comment.