-
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.
(feat) Tempo detector post route working in sending response to client
- Loading branch information
1 parent
69d23a3
commit c54db69
Showing
3 changed files
with
53 additions
and
40 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
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,43 +1,13 @@ | ||
# Importing librosa. | ||
import librosa | ||
|
||
def find_tempo(filename): | ||
y, sr = librosa.load(filename) | ||
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.' | ||
|
||
# Importing our audio file as filename. | ||
filename = "/Users/gabrielparizet/Desktop/Sound_Data/api/audio_files/donato_dozzy_your_eyes.mp3" | ||
|
||
|
||
# Load our audiofile in librosa. | ||
y, sr = librosa.load(filename) | ||
|
||
|
||
# Find the tempo and the beat_frames from our audiofile with librosa beat_track method. | ||
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr) | ||
|
||
|
||
# The format_temp function takes a float as argument and rounds it to two decimals. | ||
def format_tempo(float): | ||
float = "{:.2f}".format(float) | ||
return float | ||
|
||
|
||
# Get the duration of our audiofile in seconds with librosa get_duration method. | ||
duration = librosa.get_duration(y=y, sr=sr) | ||
|
||
|
||
# The seconds_to_minutes function takes time in float as an argument and converts it to string giving its time in minutes and seconds. | ||
def seconds_to_minutes (time): | ||
formated = "{:.2f}".format(time/60) | ||
formated = str(formated) | ||
x = formated.split('.') | ||
minutes = x[0] | ||
seconds = x[1] | ||
return f'{minutes} minutes and {seconds} seconds' | ||
|
||
|
||
# Function calls: | ||
file_duration = seconds_to_minutes(duration) | ||
file_tempo = format_tempo(tempo) | ||
|
||
|
||
print(f'Your audio file tempo is of {file_tempo} bpm.') | ||
print(f'Your audio file is {file_duration} long.') | ||
return float |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Importing librosa. | ||
import librosa | ||
|
||
|
||
# Importing our audio file as filename. | ||
filename = "/Users/gabrielparizet/Desktop/Sound_Data/api/audio_files/donato_dozzy_your_eyes.mp3" | ||
|
||
|
||
# Load our audiofile in librosa. | ||
y, sr = librosa.load(filename) | ||
|
||
# Find the tempo and the beat_frames from our audiofile with librosa beat_track method. | ||
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr) | ||
|
||
|
||
# The format_temp function takes a float as argument and rounds it to two decimals. | ||
def format_tempo(float): | ||
float = "{:.2f}".format(float) | ||
return float | ||
|
||
|
||
# Get the duration of our audiofile in seconds with librosa get_duration method. | ||
duration = librosa.get_duration(y=y, sr=sr) | ||
|
||
|
||
# The seconds_to_minutes function takes time in float as an argument and converts it to string giving its time in minutes and seconds. | ||
def seconds_to_minutes (time): | ||
formated = "{:.2f}".format(time/60) | ||
formated = str(formated) | ||
x = formated.split('.') | ||
minutes = x[0] | ||
seconds = x[1] | ||
return f'{minutes} minutes and {seconds} seconds' | ||
|
||
|
||
# Function calls: | ||
file_duration = seconds_to_minutes(duration) | ||
file_tempo = format_tempo(tempo) | ||
|
||
|
||
print(f'Your audio file tempo is of {file_tempo} bpm.') | ||
print(f'Your audio file is {file_duration} long.') |