1010
1111
1212def visualize_vertical (
13- stream , chunk , rate , alpha , window , smoothed_fft , stop_event ):
13+ stream , chunk , rate , alpha , window , smoothed_fft ,
14+ stop_event , theme = None ):
1415 """
1516 Visualizes audio data in a horizontal vertical bar chart.
1617
@@ -21,7 +22,8 @@ def visualize_vertical(
2122 alpha (float): Smoothing factor for the visualization.
2223 window (np.array): Window function to apply the audio data.
2324 smoothed_fft (np.array): Array to store the smoothed FFT values.
24- stop_event (Event): Event to signal when teh visualization should stop.
25+ stop_event (Event): Event to signal when the visualization should stop.
26+ theme (dict, optional): Contains color settings.
2527 """
2628 # Initialize smoothed FFT with zeros
2729 smoothed_fft = np .zeros (chunk // 2 + 1 )
@@ -46,14 +48,32 @@ def visualize_vertical(
4648 scaled_fft = np .int16 ((smoothed_fft / max_fft ) * rows )
4749
4850 frame_buffer = [' ' * cols for _ in range (rows )]
51+
52+ # Clear the terminal
53+ os .system ('cls' if os .name == 'nt' else 'clear' )
54+
55+ if theme :
56+ if 'background_color' in theme and (
57+ theme ['background_color' ] != 'default' ):
58+ bg_color = tuple (
59+ map (int , theme ['background_color' ].split (';' )))
60+ # Set background color
61+ print (f"\033 [48;2;{ bg_color [0 ]} ;{
62+ bg_color [1 ]} ;{ bg_color [2 ]} m" , end = '' )
63+
64+ if 'bar_color' in theme and theme ['bar_color' ] != 'default' :
65+ bar_color = tuple (map (int , theme ['bar_color' ].split (';' )))
66+ # set bar color
67+ print (f"\033 [38;2;{
68+ bar_color [0 ]} ;{ bar_color [1 ]} ;{ bar_color [2 ]} m" , end = '' )
69+
4970 for col in range (min (cols , len (scaled_fft ))):
5071 bar_height = scaled_fft [col ]
5172 for row in range (rows - bar_height , rows ):
5273 frame_buffer [row ] = frame_buffer [row ][:col ] + \
5374 '█' + frame_buffer [row ][col + 1 :]
5475
55- os .system ('cls' if os .name == 'nt' else 'clear' )
56- print ('\n ' .join (frame_buffer ), end = '' , flush = True )
76+ print ('\n ' .join (frame_buffer ), end = '\033 [0m' , flush = True )
5777
5878 time .sleep (0.1 ) # control frame rate
5979
0 commit comments