new redis keys in redisplay and variable refresh rate
This commit is contained in:
parent
12b1a3312e
commit
99957e789d
32
redisplay.py
32
redisplay.py
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""
|
"""
|
||||||
Redisplay: Live Audio Spectrum Analyzer
|
Redisplay: Redilysis Audio Analysis UI
|
||||||
|
v0.2
|
||||||
|
|
||||||
This script provides a real-time audio visualization tool featuring a spectrum
|
This script provides a real-time audio visualization tool featuring a spectrum
|
||||||
analyzer, a waveform display, and multi-band VU meters. It captures audio from a
|
analyzer, a waveform display, and multi-band VU meters. It captures audio from a
|
||||||
@ -10,13 +11,20 @@ GUI built with Tkinter.
|
|||||||
Key Features:
|
Key Features:
|
||||||
- Live waveform and spectrum plotting using Matplotlib.
|
- Live waveform and spectrum plotting using Matplotlib.
|
||||||
- Configurable audio parameters (sample rate, window size).
|
- Configurable audio parameters (sample rate, window size).
|
||||||
|
- Variable display refresh rate.
|
||||||
- Device selection from available system audio inputs.
|
- Device selection from available system audio inputs.
|
||||||
- VU meters for different frequency bands.
|
- VU meters for different frequency bands.
|
||||||
- Pushes computed spectrum data (10 frequency bins) and rms to a Redis server.
|
- Pushes analysis data to Redis, including spectrum, waveform, RMS, and frequency bins.
|
||||||
- Dark theme for the GUI using sv_ttk.
|
- Dark theme for the GUI using sv_ttk.
|
||||||
|
|
||||||
|
Redis Keys:
|
||||||
|
- 'Db': The full magnitude spectrum data (NumPy array, serialized to bytes).
|
||||||
|
- 'wave': The raw audio waveform data (NumPy array, serialized to bytes).
|
||||||
|
- 'spectrum_10': A string representation of a list of levels for the VU meter frequency bins (0-10).
|
||||||
|
- 'rms': The Root Mean Square of the raw audio signal (string).
|
||||||
|
|
||||||
Author: Sam
|
Author: Sam
|
||||||
Date: 2025-07-14
|
Date: 2025-07-15
|
||||||
License: to be defined
|
License: to be defined
|
||||||
"""
|
"""
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
@ -33,6 +41,8 @@ import sys
|
|||||||
import redis
|
import redis
|
||||||
from scipy.fft import rfft, rfftfreq
|
from scipy.fft import rfft, rfftfreq
|
||||||
|
|
||||||
|
refresh_rate = 25
|
||||||
|
|
||||||
class VUMeter(tk.Canvas):
|
class VUMeter(tk.Canvas):
|
||||||
def __init__(self, parent, *args, **kwargs):
|
def __init__(self, parent, *args, **kwargs):
|
||||||
super().__init__(parent, *args, **kwargs)
|
super().__init__(parent, *args, **kwargs)
|
||||||
@ -72,7 +82,7 @@ class VUMeter(tk.Canvas):
|
|||||||
class AudioPlotterApp(tk.Tk):
|
class AudioPlotterApp(tk.Tk):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.title("Live Audio Spectrum Analyzer")
|
self.title("Redilysis")
|
||||||
self.geometry("1000x700")
|
self.geometry("1000x700")
|
||||||
sv_ttk.set_theme("dark")
|
sv_ttk.set_theme("dark")
|
||||||
|
|
||||||
@ -326,7 +336,7 @@ class AudioPlotterApp(tk.Tk):
|
|||||||
samplerate=self.samplerate, callback=self.audio_callback,
|
samplerate=self.samplerate, callback=self.audio_callback,
|
||||||
blocksize=self.window_size, latency='low')
|
blocksize=self.window_size, latency='low')
|
||||||
|
|
||||||
self.animation = FuncAnimation(self.fig, self.update_plot, interval=30, blit=True, cache_frame_data=False, save_count=sys.maxsize)
|
self.animation = FuncAnimation(self.fig, self.update_plot, interval=refresh_rate, blit=True, cache_frame_data=False, save_count=sys.maxsize)
|
||||||
self.stream.start()
|
self.stream.start()
|
||||||
self.start_button.config(text="Stop")
|
self.start_button.config(text="Stop")
|
||||||
print("DEBUG: Stream started successfully.")
|
print("DEBUG: Stream started successfully.")
|
||||||
@ -389,6 +399,15 @@ class AudioPlotterApp(tk.Tk):
|
|||||||
|
|
||||||
self.update_vu_meters(np.abs(yf) / N)
|
self.update_vu_meters(np.abs(yf) / N)
|
||||||
|
|
||||||
|
# Push to Redis
|
||||||
|
if getattr(self, 'redis_conn', None):
|
||||||
|
try:
|
||||||
|
self.redis_conn.set('Db', magnitude_db.tobytes())
|
||||||
|
self.redis_conn.set('wave', data.tobytes())
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Redis error: {e}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"\nERROR in update_plot: {e}")
|
print(f"\nERROR in update_plot: {e}")
|
||||||
|
|
||||||
@ -436,7 +455,8 @@ class AudioPlotterApp(tk.Tk):
|
|||||||
# Build text representation and print once per call
|
# Build text representation and print once per call
|
||||||
self.tenbins = f"{levels}"
|
self.tenbins = f"{levels}"
|
||||||
# Debug print
|
# Debug print
|
||||||
#print(f"tenbins={self.tenbins}, rms={self.rms:.3f}")
|
# print(f"tenbins={self.tenbins}, rms={self.rms:.3f}")
|
||||||
|
# print(levels[0], levels[1], levels[2])
|
||||||
|
|
||||||
# Push to Redis
|
# Push to Redis
|
||||||
if getattr(self, 'redis_conn', None):
|
if getattr(self, 'redis_conn', None):
|
||||||
|
Loading…
Reference in New Issue
Block a user