Ivan000 commited on
Commit
19b68b4
·
verified ·
1 Parent(s): f2e2628

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
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
- fig, ax = plt.subplots(figsize=(10, 6))
45
- ax.bar(range(num_bars), heights, color=plt.cm.viridis(np.linspace(0, 1, num_bars)))
46
- ax.set_ylim(0, np.max(S))
47
- ax.axis('off')
48
- plt.savefig(f'frames/frame_{i:04d}.png', bbox_inches='tight', pad_inches=0)
49
- plt.close()
 
 
 
 
 
 
 
 
 
 
 
 
 
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