diff --git a/Amplitude-Frequency-Visualizer.py b/Amplitude-Frequency-Visualizer.py index cea1fda..a9a0f76 100644 --- a/Amplitude-Frequency-Visualizer.py +++ b/Amplitude-Frequency-Visualizer.py @@ -49,7 +49,7 @@ ], ] -_VARS["window"] = sg.Window("Mic to frequency plot + Max Level", layout, finalize=True) +_VARS["window"] = sg.Window("Mic to frequency plot + Max Level", layout,icon="icons/amp-freq.ico", finalize=True) graph = _VARS["window"]["graph"] # INIT vars: diff --git a/Intensity-vs-Frequency-and-time.py b/Intensity-vs-Frequency-and-time.py index 1877d13..95f473e 100644 --- a/Intensity-vs-Frequency-and-time.py +++ b/Intensity-vs-Frequency-and-time.py @@ -1,190 +1,190 @@ -import PySimpleGUI as sg -import pyaudio -import numpy as np -import scipy.fft -import matplotlib.pyplot as plt -from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg -import subprocess - -"""Realtime Sound Intensity vs Frequency heatmap""" - -# VARS CONSTS: -_VARS = {"window": False, "stream": False, "audioData": np.array([]), "current_visualizer_process": None} - -# pysimpleGUI INIT: -AppFont = "Any 16" -sg.theme("DarkBlue3") - -# Heatmap plot: -layout = [ - - [ - sg.Graph( - canvas_size=(500, 500), - graph_bottom_left=(-2, -2), - graph_top_right=(102, 102), - background_color="#809AB6", - key="graph", - ) - ], - [sg.ProgressBar(4000, orientation="h", size=(20, 20), key="-PROG-")], - [ - sg.Button("Listen", font=AppFont), - sg.Button("Stop", font=AppFont, disabled=True), - sg.Button("Exit", font=AppFont), - ], -] -_VARS["window"] = sg.Window("Mic to Sound Intensity vs Frequency heatmap", layout, finalize=True) -graph = _VARS["window"]["graph"] - -# INIT vars: -CHUNK = 1024 # Samples: 1024, 512, 256, 128 -RATE = 44100 # Equivalent to Human Hearing at 40 kHz -INTERVAL = 1 # Sampling Interval in Seconds -> Interval to listen -TIMEOUT = 10 # In ms for the event loop -pAud = pyaudio.PyAudio() - -# PySimpleGUI plots: -def drawHeatMapWithLabels(intensity_data): - graph.erase() # Clear previous heatmap - rows, cols = intensity_data.shape - - # Draw labels for frequency axis - for row in range(rows): - graph.DrawText(f"{row * (RATE / 2) / rows:.0f} Hz", (105, 100 - row * 100 / rows)) - - # Draw labels for time axis - for col in range(cols): - graph.DrawText(f"{col * INTERVAL:.1f} sec", (col * 100 / cols, -5)) - - # Draw heatmap - for row in range(rows): - for col in range(cols): - intensity = intensity_data[row, col] - color = getHeatMapColor(intensity) - x1 = col * 100 / cols - y1 = 100 - (row + 1) * 100 / rows - x2 = x1 + 100 / cols - y2 = y1 + 100 / rows - graph.DrawRectangle((x1, y1), (x2, y2), line_color=color, fill_color=color) - -# pyaudio stream: -def stop(): - if _VARS["stream"]: - _VARS["stream"].stop_stream() - _VARS["stream"].close() - _VARS["stream"] = None - _VARS["window"]["-PROG-"].update(0) - _VARS["window"]["Stop"].Update(disabled=True) - _VARS["window"]["Listen"].Update(disabled=False) - -# callback: -def callback(in_data, frame_count, time_info, status): - _VARS["audioData"] = np.frombuffer(in_data, dtype=np.int16) - return (in_data, pyaudio.paContinue) - -def listen(): - _VARS["window"]["Stop"].Update(disabled=False) - _VARS["window"]["Listen"].Update(disabled=True) - _VARS["stream"] = pAud.open( - format=pyaudio.paInt16, - channels=1, - rate=RATE, - input=True, - frames_per_buffer=CHUNK, - stream_callback=callback, - ) - _VARS["stream"].start_stream() - -def close_current_visualizer(): - if _VARS["current_visualizer_process"] and _VARS["current_visualizer_process"].poll() is None: - _VARS["current_visualizer_process"].kill() - -# INIT: - -def initHeatMap(graph, rate, interval, rows, cols): - - # Clear previous drawing - - graph.erase() - - #Initial setup for the heatmap - - for row in range(rows): - - graph.DrawText(f"{row * (rate / 2) / rows:.0f} Hz", (105, 100 - row * 100 / rows)) - - - - # Draw labels for time axis - - for col in range(cols): - - graph.DrawText(f"{col * interval:.1f} sec", (col * 100 / cols, -5)) - - - -# Call the initHeatMap function to initialize the heatmap - -rows = 10 # Number of rows in the heatmap - -cols = 10 # Number of columns in the heatmap - -initHeatMap(graph, RATE, INTERVAL, rows, cols) - -# Function to get heatmap color -def getHeatMapColor(intensity, threshold=0.0, cmap=None): - # Default color map - if cmap is None: - cmap = ["#0000ff", "#00ff00", "#ffff00", "#ff0000"] # Blue to Red gradient - - # Determining color based on intensity and thresholds - if np.isnan(intensity): - return "#808080" # Gray color for NaN values - else: - # Normalizing intensity to fit within the colormap range - intensity_norm = np.log1p(intensity) / 20 # Logarithmic scale for better visualization - color_index = min(int(intensity_norm * len(cmap)), len(cmap) - 1) - return cmap[color_index] - -def compute_intensity_data(audio_data, window_size=1024, hop_size=512): - num_frames = len(audio_data) // hop_size - intensity_data = np.zeros((num_frames, window_size // 2)) - - for i in range(num_frames): - frame = audio_data[i * hop_size: (i + 1) * hop_size] - intensity_data[i, :] = np.abs(np.fft.fft(frame)[:window_size // 2]) # Magnitude spectrum - return intensity_data - -# MAIN LOOP -while True: - event, values = _VARS["window"].read(timeout=TIMEOUT) - if event in (sg.WIN_CLOSED, "Exit"): - close_current_visualizer() - stop() - pAud.terminate() - break - # for handling the closing of application - if event == sg.WIN_CLOSED : - _VARS["stream"].stop_stream() - _VARS["stream"].close() - pAud.terminate() - break - if event == "Listen": - listen() - if event == "Stop": - stop() - - # Along with the global audioData variable, this - # bit updates the waveform plot - elif _VARS["audioData"].size != 0: - # Update volume meter - _VARS["window"]["-PROG-"].update(np.amax(_VARS["audioData"])) - - # Compute intensity data for heatmap - intensity_data = compute_intensity_data(_VARS["audioData"]) - - # Draw heatmap - drawHeatMapWithLabels(intensity_data) - -_VARS["window"].close() +import PySimpleGUI as sg +import pyaudio +import numpy as np +import scipy.fft +import matplotlib.pyplot as plt +from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg +import subprocess + +"""Realtime Sound Intensity vs Frequency heatmap""" + +# VARS CONSTS: +_VARS = {"window": False, "stream": False, "audioData": np.array([]), "current_visualizer_process": None} + +# pysimpleGUI INIT: +AppFont = "Any 16" +sg.theme("DarkBlue3") + +# Heatmap plot: +layout = [ + + [ + sg.Graph( + canvas_size=(500, 500), + graph_bottom_left=(-2, -2), + graph_top_right=(102, 102), + background_color="#809AB6", + key="graph", + ) + ], + [sg.ProgressBar(4000, orientation="h", size=(20, 20), key="-PROG-")], + [ + sg.Button("Listen", font=AppFont), + sg.Button("Stop", font=AppFont, disabled=True), + sg.Button("Exit", font=AppFont), + ], +] +_VARS["window"] = sg.Window("Mic to Sound Intensity vs Frequency heatmap", layout,icon="icons/inten-vs-freq.ico", finalize=True) +graph = _VARS["window"]["graph"] + +# INIT vars: +CHUNK = 1024 # Samples: 1024, 512, 256, 128 +RATE = 44100 # Equivalent to Human Hearing at 40 kHz +INTERVAL = 1 # Sampling Interval in Seconds -> Interval to listen +TIMEOUT = 10 # In ms for the event loop +pAud = pyaudio.PyAudio() + +# PySimpleGUI plots: +def drawHeatMapWithLabels(intensity_data): + graph.erase() # Clear previous heatmap + rows, cols = intensity_data.shape + + # Draw labels for frequency axis + for row in range(rows): + graph.DrawText(f"{row * (RATE / 2) / rows:.0f} Hz", (105, 100 - row * 100 / rows)) + + # Draw labels for time axis + for col in range(cols): + graph.DrawText(f"{col * INTERVAL:.1f} sec", (col * 100 / cols, -5)) + + # Draw heatmap + for row in range(rows): + for col in range(cols): + intensity = intensity_data[row, col] + color = getHeatMapColor(intensity) + x1 = col * 100 / cols + y1 = 100 - (row + 1) * 100 / rows + x2 = x1 + 100 / cols + y2 = y1 + 100 / rows + graph.DrawRectangle((x1, y1), (x2, y2), line_color=color, fill_color=color) + +# pyaudio stream: +def stop(): + if _VARS["stream"]: + _VARS["stream"].stop_stream() + _VARS["stream"].close() + _VARS["stream"] = None + _VARS["window"]["-PROG-"].update(0) + _VARS["window"]["Stop"].Update(disabled=True) + _VARS["window"]["Listen"].Update(disabled=False) + +# callback: +def callback(in_data, frame_count, time_info, status): + _VARS["audioData"] = np.frombuffer(in_data, dtype=np.int16) + return (in_data, pyaudio.paContinue) + +def listen(): + _VARS["window"]["Stop"].Update(disabled=False) + _VARS["window"]["Listen"].Update(disabled=True) + _VARS["stream"] = pAud.open( + format=pyaudio.paInt16, + channels=1, + rate=RATE, + input=True, + frames_per_buffer=CHUNK, + stream_callback=callback, + ) + _VARS["stream"].start_stream() + +def close_current_visualizer(): + if _VARS["current_visualizer_process"] and _VARS["current_visualizer_process"].poll() is None: + _VARS["current_visualizer_process"].kill() + +# INIT: + +def initHeatMap(graph, rate, interval, rows, cols): + + # Clear previous drawing + + graph.erase() + + #Initial setup for the heatmap + + for row in range(rows): + + graph.DrawText(f"{row * (rate / 2) / rows:.0f} Hz", (105, 100 - row * 100 / rows)) + + + + # Draw labels for time axis + + for col in range(cols): + + graph.DrawText(f"{col * interval:.1f} sec", (col * 100 / cols, -5)) + + + +# Call the initHeatMap function to initialize the heatmap + +rows = 10 # Number of rows in the heatmap + +cols = 10 # Number of columns in the heatmap + +initHeatMap(graph, RATE, INTERVAL, rows, cols) + +# Function to get heatmap color +def getHeatMapColor(intensity, threshold=0.0, cmap=None): + # Default color map + if cmap is None: + cmap = ["#0000ff", "#00ff00", "#ffff00", "#ff0000"] # Blue to Red gradient + + # Determining color based on intensity and thresholds + if np.isnan(intensity): + return "#808080" # Gray color for NaN values + else: + # Normalizing intensity to fit within the colormap range + intensity_norm = np.log1p(intensity) / 20 # Logarithmic scale for better visualization + color_index = min(int(intensity_norm * len(cmap)), len(cmap) - 1) + return cmap[color_index] + +def compute_intensity_data(audio_data, window_size=1024, hop_size=512): + num_frames = len(audio_data) // hop_size + intensity_data = np.zeros((num_frames, window_size // 2)) + + for i in range(num_frames): + frame = audio_data[i * hop_size: (i + 1) * hop_size] + intensity_data[i, :] = np.abs(np.fft.fft(frame)[:window_size // 2]) # Magnitude spectrum + return intensity_data + +# MAIN LOOP +while True: + event, values = _VARS["window"].read(timeout=TIMEOUT) + if event in (sg.WIN_CLOSED, "Exit"): + close_current_visualizer() + stop() + pAud.terminate() + break + # for handling the closing of application + if event == sg.WIN_CLOSED : + _VARS["stream"].stop_stream() + _VARS["stream"].close() + pAud.terminate() + break + if event == "Listen": + listen() + if event == "Stop": + stop() + + # Along with the global audioData variable, this + # bit updates the waveform plot + elif _VARS["audioData"].size != 0: + # Update volume meter + _VARS["window"]["-PROG-"].update(np.amax(_VARS["audioData"])) + + # Compute intensity data for heatmap + intensity_data = compute_intensity_data(_VARS["audioData"]) + + # Draw heatmap + drawHeatMapWithLabels(intensity_data) + +_VARS["window"].close() diff --git a/Spectrogram.py b/Spectrogram.py index 59744f5..49401b7 100644 --- a/Spectrogram.py +++ b/Spectrogram.py @@ -1,169 +1,169 @@ -import PySimpleGUI as sg -import pyaudio -import numpy as np -import scipy.signal -import matplotlib.pyplot as plt -from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg -import subprocess - - - -""" RealTime Audio Spectrogram plot """ - -# VARS CONSTS: -_VARS = {"window": False, "stream": False, "audioData": np.array([]), "current_visualizer_process": None} - -# pysimpleGUI INIT: -AppFont = "Any 16" -sg.theme("DarkBlue3") - -menu_layout = [ - ['Run Visualizers', ['Amplitude-Frequency-Visualizer', 'Waveform', 'Spectrogram', 'Intensity-vs-Frequency-and-time']], -] - -layout = [ - [sg.Menu(menu_layout)], - [ - sg.Graph( - canvas_size=(500, 500), - graph_bottom_left=(-2, -2), - graph_top_right=(102, 102), - background_color="#809AB6", - key="graph", - ) - ], - [sg.ProgressBar(4000, orientation="h", size=(20, 20), key="-PROG-")], - [ - sg.Button("Listen", font=AppFont), - sg.Button("Stop", font=AppFont, disabled=True), - sg.Button("Save", font=AppFont, disabled=True), - sg.Button("Exit", font=AppFont), - ], -] -_VARS["window"] = sg.Window("Mic to spectrogram plot + Max Level", layout, finalize=True) -graph = _VARS["window"]["graph"] - -# INIT vars: -CHUNK = 1024 # Samples: 1024, 512, 256, 128 -RATE = 44100 # Equivalent to Human Hearing at 40 kHz -INTERVAL = 1 # Sampling Interval in Seconds -> Interval to listen -TIMEOUT = 10 # In ms for the event loop -pAud = pyaudio.PyAudio() - -try: - pAud.get_device_info_by_index(0) -except pyaudio.CoreError as e: - print(f"Error initializing PyAudio: {e}") - pAud = None - -# FUNCTIONS: - -# PySimpleGUI plots: -def draw_figure(canvas, figure): - figure_canvas_agg = FigureCanvasTkAgg(figure, canvas) - figure_canvas_agg.draw() - figure_canvas_agg.get_tk_widget().pack(side="top", fill="both", expand=1) - return figure_canvas_agg - - -# pyaudio stream: -def stop(): - if _VARS["stream"]: - _VARS["stream"].stop_stream() - _VARS["stream"].close() - _VARS["stream"] = None - _VARS["window"]["-PROG-"].update(0) - _VARS["window"]["Stop"].Update(disabled=True) - _VARS["window"]["Listen"].Update(disabled=False) - _VARS["window"]["Save"].Update(disabled=True) - -# callback: -def callback(in_data, frame_count, time_info, status): - _VARS["audioData"] = np.frombuffer(in_data, dtype=np.int16) - return (in_data, pyaudio.paContinue) - -def listen(): - _VARS["window"]["Stop"].Update(disabled=False) - _VARS["window"]["Listen"].Update(disabled=True) - _VARS["window"]["Save"].Update(disabled=False) - _VARS["stream"] = pAud.open( - format=pyaudio.paInt16, - channels=1, - rate=RATE, - input=True, - frames_per_buffer=CHUNK, - stream_callback=callback, - ) - _VARS["stream"].start_stream() - -def close_current_visualizer(): - if _VARS["current_visualizer_process"] and _VARS["current_visualizer_process"].poll() is None: - _VARS["current_visualizer_process"].kill() - -def save_spectrogram(): - file_path = sg.popup_get_file('Save as', save_as=True, no_window=True, file_types=(("PNG Files", "*.png"), ("All Files", "*.*"))) - if file_path: - fig.savefig(file_path) - sg.popup("File saved!", title="Success") - -# INIT: -fig, ax = plt.subplots() # create a figure and an axis object -fig_agg = draw_figure(graph.TKCanvas, fig) # draw the figure on the graph - - -# MAIN LOOP -while True: - event, values = _VARS["window"].read(timeout=TIMEOUT) - if event in (sg.WIN_CLOSED, "Exit"): - close_current_visualizer() - stop() - pAud.terminate() - break - - if event == "Listen": - listen() - - if event == "Stop": - stop() - - if event == "Save": - save_spectrogram() - - if event == 'Amplitude-Frequency-Visualizer': - close_current_visualizer() - _VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Amplitude-Frequency-Visualizer.py']) - _VARS["window"].close() - break - if event == 'Waveform': - close_current_visualizer() - _VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Waveform.py']) - _VARS["window"].close() - break - if event == 'Spectogram': - close_current_visualizer() - _VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Spectogram.py']) - _VARS["window"].close() - break - if event == 'Intensity-vs-Frequency-and-time': - close_current_visualizer() - _VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Intensity-vs-Frequency-and-time.py']) - _VARS["window"].close() - break - - # Along with the global audioData variable, this - # bit updates the spectrogram plot - elif _VARS["audioData"].size != 0: - # Update volume meter - _VARS["window"]["-PROG-"].update(np.amax(_VARS["audioData"])) - # Compute spectrogram - f, t, Sxx = scipy.signal.spectrogram(_VARS["audioData"], fs=RATE) - # Plot spectrogram - ax.clear() # clear the previous plot - ax.pcolormesh( - t, f, Sxx, shading="gouraud" - ) # plot the spectrogram as a colored mesh - ax.set_ylabel("Frequency [Hz]") # set the y-axis label - ax.set_xlabel("Time [sec]") # set the x-axis label - fig_agg.draw() # redraw the figure - -_VARS["window"].close() +import PySimpleGUI as sg +import pyaudio +import numpy as np +import scipy.signal +import matplotlib.pyplot as plt +from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg +import subprocess + + + +""" RealTime Audio Spectrogram plot """ + +# VARS CONSTS: +_VARS = {"window": False, "stream": False, "audioData": np.array([]), "current_visualizer_process": None} + +# pysimpleGUI INIT: +AppFont = "Any 16" +sg.theme("DarkBlue3") + +menu_layout = [ + ['Run Visualizers', ['Amplitude-Frequency-Visualizer', 'Waveform', 'Spectrogram', 'Intensity-vs-Frequency-and-time']], +] + +layout = [ + [sg.Menu(menu_layout)], + [ + sg.Graph( + canvas_size=(500, 500), + graph_bottom_left=(-2, -2), + graph_top_right=(102, 102), + background_color="#809AB6", + key="graph", + ) + ], + [sg.ProgressBar(4000, orientation="h", size=(20, 20), key="-PROG-")], + [ + sg.Button("Listen", font=AppFont), + sg.Button("Stop", font=AppFont, disabled=True), + sg.Button("Save", font=AppFont, disabled=True), + sg.Button("Exit", font=AppFont), + ], +] +_VARS["window"] = sg.Window("Mic to spectrogram plot + Max Level", layout,icon="icons/spectrogram.ico", finalize=True) +graph = _VARS["window"]["graph"] + +# INIT vars: +CHUNK = 1024 # Samples: 1024, 512, 256, 128 +RATE = 44100 # Equivalent to Human Hearing at 40 kHz +INTERVAL = 1 # Sampling Interval in Seconds -> Interval to listen +TIMEOUT = 10 # In ms for the event loop +pAud = pyaudio.PyAudio() + +try: + pAud.get_device_info_by_index(0) +except pyaudio.CoreError as e: + print(f"Error initializing PyAudio: {e}") + pAud = None + +# FUNCTIONS: + +# PySimpleGUI plots: +def draw_figure(canvas, figure): + figure_canvas_agg = FigureCanvasTkAgg(figure, canvas) + figure_canvas_agg.draw() + figure_canvas_agg.get_tk_widget().pack(side="top", fill="both", expand=1) + return figure_canvas_agg + + +# pyaudio stream: +def stop(): + if _VARS["stream"]: + _VARS["stream"].stop_stream() + _VARS["stream"].close() + _VARS["stream"] = None + _VARS["window"]["-PROG-"].update(0) + _VARS["window"]["Stop"].Update(disabled=True) + _VARS["window"]["Listen"].Update(disabled=False) + _VARS["window"]["Save"].Update(disabled=True) + +# callback: +def callback(in_data, frame_count, time_info, status): + _VARS["audioData"] = np.frombuffer(in_data, dtype=np.int16) + return (in_data, pyaudio.paContinue) + +def listen(): + _VARS["window"]["Stop"].Update(disabled=False) + _VARS["window"]["Listen"].Update(disabled=True) + _VARS["window"]["Save"].Update(disabled=False) + _VARS["stream"] = pAud.open( + format=pyaudio.paInt16, + channels=1, + rate=RATE, + input=True, + frames_per_buffer=CHUNK, + stream_callback=callback, + ) + _VARS["stream"].start_stream() + +def close_current_visualizer(): + if _VARS["current_visualizer_process"] and _VARS["current_visualizer_process"].poll() is None: + _VARS["current_visualizer_process"].kill() + +def save_spectrogram(): + file_path = sg.popup_get_file('Save as', save_as=True, no_window=True, file_types=(("PNG Files", "*.png"), ("All Files", "*.*"))) + if file_path: + fig.savefig(file_path) + sg.popup("File saved!", title="Success") + +# INIT: +fig, ax = plt.subplots() # create a figure and an axis object +fig_agg = draw_figure(graph.TKCanvas, fig) # draw the figure on the graph + + +# MAIN LOOP +while True: + event, values = _VARS["window"].read(timeout=TIMEOUT) + if event in (sg.WIN_CLOSED, "Exit"): + close_current_visualizer() + stop() + pAud.terminate() + break + + if event == "Listen": + listen() + + if event == "Stop": + stop() + + if event == "Save": + save_spectrogram() + + if event == 'Amplitude-Frequency-Visualizer': + close_current_visualizer() + _VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Amplitude-Frequency-Visualizer.py']) + _VARS["window"].close() + break + if event == 'Waveform': + close_current_visualizer() + _VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Waveform.py']) + _VARS["window"].close() + break + if event == 'Spectogram': + close_current_visualizer() + _VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Spectogram.py']) + _VARS["window"].close() + break + if event == 'Intensity-vs-Frequency-and-time': + close_current_visualizer() + _VARS["current_visualizer_process"] = subprocess.Popen(['python', 'Intensity-vs-Frequency-and-time.py']) + _VARS["window"].close() + break + + # Along with the global audioData variable, this + # bit updates the spectrogram plot + elif _VARS["audioData"].size != 0: + # Update volume meter + _VARS["window"]["-PROG-"].update(np.amax(_VARS["audioData"])) + # Compute spectrogram + f, t, Sxx = scipy.signal.spectrogram(_VARS["audioData"], fs=RATE) + # Plot spectrogram + ax.clear() # clear the previous plot + ax.pcolormesh( + t, f, Sxx, shading="gouraud" + ) # plot the spectrogram as a colored mesh + ax.set_ylabel("Frequency [Hz]") # set the y-axis label + ax.set_xlabel("Time [sec]") # set the x-axis label + fig_agg.draw() # redraw the figure + +_VARS["window"].close() diff --git a/Waveform.py b/Waveform.py index 1ee4ebc..53a662d 100644 --- a/Waveform.py +++ b/Waveform.py @@ -29,7 +29,7 @@ sg.Button("Exit", font=AppFont), ], ] -_VARS["window"] = sg.Window("Mic to waveform plot + Max Level", layout, finalize=True) +_VARS["window"] = sg.Window("Mic to waveform plot + Max Level", layout,icon="icons/waveform.ico", finalize=True) graph = _VARS["window"]["graph"] # INIT vars: diff --git a/icons/amp-freq.ico b/icons/amp-freq.ico new file mode 100644 index 0000000..60f4999 Binary files /dev/null and b/icons/amp-freq.ico differ diff --git a/icons/inten-vs-freq.ico b/icons/inten-vs-freq.ico new file mode 100644 index 0000000..6895151 Binary files /dev/null and b/icons/inten-vs-freq.ico differ diff --git a/icons/main.ico b/icons/main.ico new file mode 100644 index 0000000..9b2030a Binary files /dev/null and b/icons/main.ico differ diff --git a/icons/spectrogram.ico b/icons/spectrogram.ico new file mode 100644 index 0000000..1c7cc5b Binary files /dev/null and b/icons/spectrogram.ico differ diff --git a/icons/waveform.ico b/icons/waveform.ico new file mode 100644 index 0000000..e575976 Binary files /dev/null and b/icons/waveform.ico differ diff --git a/mainLanding.py b/mainLanding.py index 6b2e9cf..e17a62f 100644 --- a/mainLanding.py +++ b/mainLanding.py @@ -1,79 +1,79 @@ -import PySimpleGUI as sg -import subprocess -import os - -# Create the layout for the landing page -AppFont = "Helvetica 16" - -# Function to create the main layout -def create_layout(): - return [ - [sg.Text("Welcome to SoundScape", font=("Helvetica", 24), justification="center", pad=(0, 20), expand_x=True)], - [sg.Text("Explore various audio visualizers", font=("Helvetica", 14), justification="center", pad=(0, 10), expand_x=True)], - [sg.Multiline("SoundScape is an innovative application designed to transform audio data into stunning visualizations. " - "Choose from a variety of visualizers to unleash the power of audio visualizations!.", - font=("Helvetica", 14), justification="center", size=(60, 2), no_scrollbar=True, disabled=True, pad=(20, 20), - background_color="#e1f5fe", text_color="#006064", expand_x=True, expand_y=True)], - [sg.Button("Amplitude-Frequency Visualizer", pad=(10, 10), key="Amplitude-Frequency Visualizer"), - sg.Button("Waveform", pad=(10, 10), key="Waveform"), - sg.Button("Spectrogram", pad=(10, 10), key="Spectrogram"), - sg.Button("Intensity vs Frequency and Time", pad=(10, 10), key="Intensity vs Frequency and Time")], - [sg.Button("Change Theme", pad=(10, 20), key="Change Theme", button_color=("white", "green"))], - [sg.Button("Exit", size=(80,2), pad=(10, 10), key="Exit", button_color=("white", "red"), font=("Helvetica", 12), tooltip="Exit the application")], - - ] - -# Create the main window with the initial layout -layout = create_layout() -window = sg.Window("Welcome to SoundScape ", layout, finalize=True, element_justification="center", resizable=False, size=(800, 600)) - -def close_current_visualizer(process): - if process and process.poll() is None: - process.kill() - process.wait() - -# new function made for changing the theme -def change_theme(): - print("Changing theme...") - current_theme = sg.theme_list() - current_theme_index = current_theme.index(sg.theme()) - next_theme_index = (current_theme_index + 1) % len(current_theme) - sg.theme(current_theme[next_theme_index]) - - global window - layout = create_layout() # layout chanfing - window.close() - window = sg.Window("Welcome to SoundScape ", layout, finalize=True, element_justification="center", resizable=False, size=(800, 600)) - - print("Theme changed to:", current_theme[next_theme_index]) - -# Main loop -current_visualizer_process = None -while True: - event, values = window.read() - - if event in (sg.WIN_CLOSED, "Exit"): - close_current_visualizer(current_visualizer_process) - break - - if event == "Change Theme": - change_theme() - - visualizer_scripts = { - "Amplitude-Frequency Visualizer": "Amplitude-Frequency-Visualizer.py", - "Waveform": "Waveform.py", - "Spectrogram": "Spectogram.py", - "Intensity vs Frequency and Time": "Intensity-vs-Frequency-and-Time.py" - } - - if event in visualizer_scripts: - script_path = visualizer_scripts[event] - if os.path.exists(script_path): - close_current_visualizer(current_visualizer_process) - current_visualizer_process = subprocess.Popen(['python', script_path]) - window.close() - break - else: - sg.popup_error(f"Script '{script_path}' not found!", title="File Not Found") - +import PySimpleGUI as sg +import subprocess +import os + +# Create the layout for the landing page +AppFont = "Helvetica 16" + +# Function to create the main layout +def create_layout(): + return [ + [sg.Text("Welcome to SoundScape", font=("Helvetica", 24), justification="center", pad=(0, 20), expand_x=True)], + [sg.Text("Explore various audio visualizers", font=("Helvetica", 14), justification="center", pad=(0, 10), expand_x=True)], + [sg.Multiline("SoundScape is an innovative application designed to transform audio data into stunning visualizations. " + "Choose from a variety of visualizers to unleash the power of audio visualizations!.", + font=("Helvetica", 14), justification="center", size=(60, 2), no_scrollbar=True, disabled=True, pad=(20, 20), + background_color="#e1f5fe", text_color="#006064", expand_x=True, expand_y=True)], + [sg.Button("Amplitude-Frequency Visualizer", pad=(10, 10), key="Amplitude-Frequency Visualizer"), + sg.Button("Waveform", pad=(10, 10), key="Waveform"), + sg.Button("Spectrogram", pad=(10, 10), key="Spectrogram"), + sg.Button("Intensity vs Frequency and Time", pad=(10, 10), key="Intensity vs Frequency and Time")], + [sg.Button("Change Theme", pad=(10, 20), key="Change Theme", button_color=("white", "green"))], + [sg.Button("Exit", size=(80,2), pad=(10, 10), key="Exit", button_color=("white", "red"), font=("Helvetica", 12), tooltip="Exit the application")], + + ] + +# Create the main window with the initial layout +layout = create_layout() +window = sg.Window("Welcome to SoundScape ", layout,icon="icons/main.ico", finalize=True, element_justification="center", resizable=False, size=(800, 600)) + +def close_current_visualizer(process): + if process and process.poll() is None: + process.kill() + process.wait() + +# new function made for changing the theme +def change_theme(): + print("Changing theme...") + current_theme = sg.theme_list() + current_theme_index = current_theme.index(sg.theme()) + next_theme_index = (current_theme_index + 1) % len(current_theme) + sg.theme(current_theme[next_theme_index]) + + global window + layout = create_layout() # layout chanfing + window.close() + window = sg.Window("Welcome to SoundScape ", layout, finalize=True, element_justification="center", resizable=False, size=(800, 600)) + + print("Theme changed to:", current_theme[next_theme_index]) + +# Main loop +current_visualizer_process = None +while True: + event, values = window.read() + + if event in (sg.WIN_CLOSED, "Exit"): + close_current_visualizer(current_visualizer_process) + break + + if event == "Change Theme": + change_theme() + + visualizer_scripts = { + "Amplitude-Frequency Visualizer": "Amplitude-Frequency-Visualizer.py", + "Waveform": "Waveform.py", + "Spectrogram": "Spectogram.py", + "Intensity vs Frequency and Time": "Intensity-vs-Frequency-and-Time.py" + } + + if event in visualizer_scripts: + script_path = visualizer_scripts[event] + if os.path.exists(script_path): + close_current_visualizer(current_visualizer_process) + current_visualizer_process = subprocess.Popen(['python', script_path]) + window.close() + break + else: + sg.popup_error(f"Script '{script_path}' not found!", title="File Not Found") + window.close() \ No newline at end of file