Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ def get_segment(audio, sr):
|
|
| 16 |
|
| 17 |
# If no onsets are detected, return a segment from the beginning
|
| 18 |
if len(onset_frames) == 0:
|
| 19 |
-
return audio[:2048] # Return the first segment of 1 second
|
| 20 |
|
| 21 |
# Calculate energy over time
|
| 22 |
energy = np.array([np.sum(np.abs(audio[i:i + 2048]**2)) for i in range(0, len(audio), 2048)])
|
|
@@ -36,14 +36,14 @@ def get_segment(audio, sr):
|
|
| 36 |
end_sample = min(start_sample + segment_length, len(audio))
|
| 37 |
|
| 38 |
# Return the selected segment
|
| 39 |
-
return audio[start_sample:end_sample]
|
| 40 |
|
| 41 |
# Function to extend music by adding silence
|
| 42 |
def extend_music(file, added_minutes):
|
| 43 |
audio, sr = load_audio(file)
|
| 44 |
|
| 45 |
# Get a relevant segment from the audio
|
| 46 |
-
segment = get_segment(audio, sr)
|
| 47 |
|
| 48 |
# Calculate the number of samples to add based on the duration in minutes
|
| 49 |
additional_samples = int(added_minutes * 60 * sr)
|
|
@@ -51,7 +51,8 @@ def extend_music(file, added_minutes):
|
|
| 51 |
|
| 52 |
# Normalize audio to the range of [-1, 1]
|
| 53 |
extended_audio = extended_audio / np.max(np.abs(extended_audio)) # Avoid overflow
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
# Gradio UI setup
|
| 57 |
with gr.Blocks() as app:
|
|
|
|
| 16 |
|
| 17 |
# If no onsets are detected, return a segment from the beginning
|
| 18 |
if len(onset_frames) == 0:
|
| 19 |
+
return audio[:2048], sr # Return the first segment of 1 second
|
| 20 |
|
| 21 |
# Calculate energy over time
|
| 22 |
energy = np.array([np.sum(np.abs(audio[i:i + 2048]**2)) for i in range(0, len(audio), 2048)])
|
|
|
|
| 36 |
end_sample = min(start_sample + segment_length, len(audio))
|
| 37 |
|
| 38 |
# Return the selected segment
|
| 39 |
+
return audio[start_sample:end_sample], sr
|
| 40 |
|
| 41 |
# Function to extend music by adding silence
|
| 42 |
def extend_music(file, added_minutes):
|
| 43 |
audio, sr = load_audio(file)
|
| 44 |
|
| 45 |
# Get a relevant segment from the audio
|
| 46 |
+
segment, sr = get_segment(audio, sr)
|
| 47 |
|
| 48 |
# Calculate the number of samples to add based on the duration in minutes
|
| 49 |
additional_samples = int(added_minutes * 60 * sr)
|
|
|
|
| 51 |
|
| 52 |
# Normalize audio to the range of [-1, 1]
|
| 53 |
extended_audio = extended_audio / np.max(np.abs(extended_audio)) # Avoid overflow
|
| 54 |
+
|
| 55 |
+
return extended_audio.astype(np.float32), sr # Return audio and sample rate
|
| 56 |
|
| 57 |
# Gradio UI setup
|
| 58 |
with gr.Blocks() as app:
|