root commited on
Commit
bc0fbf6
·
1 Parent(s): 8df3af9
Files changed (1) hide show
  1. utils.py +24 -19
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(duration_seconds):
41
- """Calculate appropriate lyrics length based on audio duration."""
 
 
 
 
 
 
42
  # Convert duration to minutes
43
- duration_minutes = duration_seconds / 60
44
 
45
  # Calculate total words based on duration
46
- # Using 90 words per minute (doubled from 45)
47
- words_per_minute = 90
48
- total_words = int(duration_minutes * words_per_minute)
49
 
50
- # Calculate number of lines based on average words per line
51
- # Using 8-10 words per line
52
- words_per_line = 9
53
- total_lines = int(total_words / words_per_line)
54
 
55
- # Adjust number of lines based on song structure
56
- if total_lines <= 6:
57
- # Very short song - one verse and chorus
58
- return 4 # 2 lines verse + 2 lines chorus
59
- elif total_lines <= 10:
60
  # Short song - one verse and chorus
61
- return 5 # 3 lines verse + 2 lines chorus
62
- elif total_lines <= 15:
63
  # Medium song - two verses and chorus
64
- return 8 # 3 lines verse + 2 lines chorus + 3 lines verse
65
  else:
66
  # Longer song - two verses, chorus, and bridge
67
- return 10 # 3 lines verse + 2 lines chorus + 2 lines bridge + 3 lines verse
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."""