-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update sound_detector.py by adding comments
- Loading branch information
1 parent
c54db69
commit e5bf73e
Showing
1 changed file
with
7 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|