Spaces:
Runtime error
Runtime error
root
commited on
Commit
·
bc0fbf6
1
Parent(s):
8df3af9
ss
Browse files
utils.py
CHANGED
@@ -37,34 +37,39 @@ def extract_mfcc_features(y, sr, n_mfcc=20):
|
|
37 |
# Return a fallback feature vector if extraction fails
|
38 |
return np.zeros(n_mfcc)
|
39 |
|
40 |
-
def calculate_lyrics_length(
|
41 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
# Convert duration to minutes
|
43 |
-
duration_minutes =
|
44 |
|
45 |
# Calculate total words based on duration
|
46 |
-
# Using
|
47 |
-
|
48 |
-
total_words = int(duration_minutes * words_per_minute)
|
49 |
|
50 |
-
# Calculate number of lines
|
51 |
-
#
|
52 |
-
words_per_line = 9
|
53 |
-
total_lines =
|
54 |
|
55 |
-
# Adjust
|
56 |
-
if total_lines
|
57 |
-
# Very short song -
|
58 |
-
return
|
59 |
-
elif total_lines
|
60 |
# Short song - one verse and chorus
|
61 |
-
return
|
62 |
-
elif total_lines
|
63 |
# Medium song - two verses and chorus
|
64 |
-
return
|
65 |
else:
|
66 |
# Longer song - two verses, chorus, and bridge
|
67 |
-
return
|
68 |
|
69 |
def format_genre_results(top_genres):
|
70 |
"""Format genre classification results for display."""
|
|
|
37 |
# Return a fallback feature vector if extraction fails
|
38 |
return np.zeros(n_mfcc)
|
39 |
|
40 |
+
def calculate_lyrics_length(duration):
|
41 |
+
"""
|
42 |
+
Calculate appropriate lyrics length based on audio duration.
|
43 |
+
Uses a more conservative calculation that generates shorter lyrics:
|
44 |
+
- Average words per line (8-10 words)
|
45 |
+
- Reduced words per minute (45 words instead of 135)
|
46 |
+
- Simplified song structure
|
47 |
+
"""
|
48 |
# Convert duration to minutes
|
49 |
+
duration_minutes = duration / 60
|
50 |
|
51 |
# Calculate total words based on duration
|
52 |
+
# Using 45 words per minute (reduced from 135)
|
53 |
+
total_words = int(duration_minutes * 45)
|
|
|
54 |
|
55 |
+
# Calculate number of lines
|
56 |
+
# Assuming 8-10 words per line
|
57 |
+
words_per_line = 9 # average
|
58 |
+
total_lines = total_words // words_per_line
|
59 |
|
60 |
+
# Adjust for song structure with shorter lengths
|
61 |
+
if total_lines < 6:
|
62 |
+
# Very short song - keep it simple
|
63 |
+
return max(2, total_lines)
|
64 |
+
elif total_lines < 10:
|
65 |
# Short song - one verse and chorus
|
66 |
+
return min(6, total_lines)
|
67 |
+
elif total_lines < 15:
|
68 |
# Medium song - two verses and chorus
|
69 |
+
return min(10, total_lines)
|
70 |
else:
|
71 |
# Longer song - two verses, chorus, and bridge
|
72 |
+
return min(15, total_lines)
|
73 |
|
74 |
def format_genre_results(top_genres):
|
75 |
"""Format genre classification results for display."""
|