Surn commited on
Commit
2cfed1b
1 Parent(s): a16c003

Fix short Melody used for longer duration generation

Browse files
Files changed (1) hide show
  1. audiocraft/utils/extend.py +6 -2
audiocraft/utils/extend.py CHANGED
@@ -25,7 +25,11 @@ def separate_audio_segments(audio, segment_duration=30, overlap=1):
25
 
26
  segments = []
27
  start_sample = 0
28
-
 
 
 
 
29
  while total_samples >= segment_samples:
30
  # Collect the segment
31
  # the end sample is the start sample plus the segment samples,
@@ -41,7 +45,7 @@ def separate_audio_segments(audio, segment_duration=30, overlap=1):
41
  if total_samples > 0:
42
  segment = audio_data[-segment_samples:]
43
  segments.append((sr, segment))
44
- print(f"separate_audio_segments: {len(segments)} segments")
45
  return segments
46
 
47
  def generate_music_segments(text, melody, seed, MODEL, duration:int=10, overlap:int=1, segment_duration:int=30, prompt_index:int=0, harmony_only:bool= False):
 
25
 
26
  segments = []
27
  start_sample = 0
28
+ # handle the case where the audio is shorter than the segment duration
29
+ if total_samples == 0:
30
+ total_samples = 1
31
+ segment_samples = len(audio_data)
32
+ overlap_samples = 0
33
  while total_samples >= segment_samples:
34
  # Collect the segment
35
  # the end sample is the start sample plus the segment samples,
 
45
  if total_samples > 0:
46
  segment = audio_data[-segment_samples:]
47
  segments.append((sr, segment))
48
+ print(f"separate_audio_segments: {len(segments)} segments of length {segment_samples // sr} seconds")
49
  return segments
50
 
51
  def generate_music_segments(text, melody, seed, MODEL, duration:int=10, overlap:int=1, segment_duration:int=30, prompt_index:int=0, harmony_only:bool= False):