Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,12 +41,25 @@ def generate_frequency_visualization(audio_path, fps, num_bars):
|
|
| 41 |
|
| 42 |
# Generate and save each frame
|
| 43 |
for i, heights in enumerate(bar_heights):
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
print(f"Generated {len(bar_heights)} frames for visualization.")
|
| 52 |
return 'frames', duration
|
|
|
|
| 41 |
|
| 42 |
# Generate and save each frame
|
| 43 |
for i, heights in enumerate(bar_heights):
|
| 44 |
+
# Create black background
|
| 45 |
+
img = np.zeros((720, 1280, 3), dtype=np.uint8)
|
| 46 |
+
|
| 47 |
+
# Normalize heights to fit the frame
|
| 48 |
+
heights = np.array(heights)
|
| 49 |
+
heights = (heights / np.max(heights) * 600).astype(int)
|
| 50 |
+
|
| 51 |
+
# Calculate bar positions
|
| 52 |
+
bar_width = 80
|
| 53 |
+
spacing = (1280 - num_bars * bar_width) // (num_bars + 1)
|
| 54 |
+
for j, height in enumerate(heights):
|
| 55 |
+
x = spacing + j * (bar_width + spacing)
|
| 56 |
+
y = 720 - height
|
| 57 |
+
color = tuple((np.array(plt.cm.viridis(j / num_bars))[:3] * 255).astype(int)) # Use Viridis colormap
|
| 58 |
+
cv2.rectangle(img, (x, 720), (x + bar_width, y), color, -1)
|
| 59 |
+
|
| 60 |
+
# Save the frame
|
| 61 |
+
frame_path = f'frames/frame_{i:04d}.png'
|
| 62 |
+
cv2.imwrite(frame_path, img)
|
| 63 |
|
| 64 |
print(f"Generated {len(bar_heights)} frames for visualization.")
|
| 65 |
return 'frames', duration
|