From 79451781a68835c5d717399c99ad6d244f1a4ca3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 19:49:36 +0000 Subject: [PATCH 1/6] Initial plan From 7e395071ace57e4bb0b0c2b952cdc5ec83d1c6b3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 19:53:11 +0000 Subject: [PATCH 2/6] Remove matplotlib display usage, generate images only Co-authored-by: hackolite <826027+hackolite@users.noreply.github.com> --- node/InputNode/spectrogram_utils.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/node/InputNode/spectrogram_utils.py b/node/InputNode/spectrogram_utils.py index 836ba391..61091ade 100644 --- a/node/InputNode/spectrogram_utils.py +++ b/node/InputNode/spectrogram_utils.py @@ -7,8 +7,11 @@ converting them to colored RGB images for better visualization and event detection. """ +import os import cv2 import numpy as np +import matplotlib +matplotlib.use('Agg') # Use non-GUI backend to prevent display import matplotlib.cm as cm from matplotlib import pyplot as plt from numpy.lib import stride_tricks @@ -237,7 +240,7 @@ def plot_spectrogram(location, plotpath=None, binsize=2**10, colormap="jet"): Args: location: Chemin du fichier audio (.wav) - plotpath: Chemin de sauvegarde de l'image (si None, affiche à l'écran) + plotpath: Chemin de sauvegarde de l'image (si None, utilise un fichier temporaire) binsize: Taille de la fenêtre FFT (par défaut 1024) colormap: Colormap matplotlib à utiliser @@ -282,11 +285,14 @@ def plot_spectrogram(location, plotpath=None, binsize=2**10, colormap="jet"): ylocs = np.int16(np.round(np.linspace(0, freqbins-1, 10))) plt.yticks(ylocs, ["%.02f" % freq[i] for i in ylocs]) - if plotpath: - plt.savefig(plotpath, bbox_inches="tight") - else: - plt.show() - + # Always save to a file instead of displaying + if plotpath is None: + # Use a temporary file if no path is provided + import tempfile + fd, plotpath = tempfile.mkstemp(suffix='.png', prefix='spectrogram_') + os.close(fd) # Close file descriptor, we'll use the path + + plt.savefig(plotpath, bbox_inches="tight") plt.clf() return ims From 45c14c2705791315fd58519d5e32ea12addecf4e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 19:53:57 +0000 Subject: [PATCH 3/6] Address code review: move tempfile import to top, use NamedTemporaryFile Co-authored-by: hackolite <826027+hackolite@users.noreply.github.com> --- node/InputNode/spectrogram_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/node/InputNode/spectrogram_utils.py b/node/InputNode/spectrogram_utils.py index 61091ade..700075b9 100644 --- a/node/InputNode/spectrogram_utils.py +++ b/node/InputNode/spectrogram_utils.py @@ -8,6 +8,7 @@ """ import os +import tempfile import cv2 import numpy as np import matplotlib @@ -288,9 +289,9 @@ def plot_spectrogram(location, plotpath=None, binsize=2**10, colormap="jet"): # Always save to a file instead of displaying if plotpath is None: # Use a temporary file if no path is provided - import tempfile - fd, plotpath = tempfile.mkstemp(suffix='.png', prefix='spectrogram_') - os.close(fd) # Close file descriptor, we'll use the path + temp_file = tempfile.NamedTemporaryFile(suffix='.png', prefix='spectrogram_', delete=False) + plotpath = temp_file.name + temp_file.close() plt.savefig(plotpath, bbox_inches="tight") plt.clf() From 4ee869f9e4894f5bcc1ba6f6302b7fc84695b513 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 19:54:51 +0000 Subject: [PATCH 4/6] Return path along with data, document temporary file cleanup Co-authored-by: hackolite <826027+hackolite@users.noreply.github.com> --- node/InputNode/spectrogram_utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/node/InputNode/spectrogram_utils.py b/node/InputNode/spectrogram_utils.py index 700075b9..04f9fe66 100644 --- a/node/InputNode/spectrogram_utils.py +++ b/node/InputNode/spectrogram_utils.py @@ -246,7 +246,13 @@ def plot_spectrogram(location, plotpath=None, binsize=2**10, colormap="jet"): colormap: Colormap matplotlib à utiliser Returns: - ims: Matrice du spectrogramme en décibels + tuple: (ims, plotpath) where: + - ims: Matrice du spectrogramme en décibels + - plotpath: Path to the saved spectrogram image (useful when temporary file is created) + + Note: + When plotpath is None, a temporary file is created with delete=False. + The caller is responsible for cleaning up the temporary file if needed. """ if wav is None: raise ImportError("scipy is required for plot_spectrogram. Install with: pip install scipy") @@ -296,7 +302,7 @@ def plot_spectrogram(location, plotpath=None, binsize=2**10, colormap="jet"): plt.savefig(plotpath, bbox_inches="tight") plt.clf() - return ims + return ims, plotpath def create_spectrogram_from_audio(audio_data, sample_rate=44100, binsize=2**10, colormap="jet"): From 5a63fee56a3ebeb5d0b9a154315b26a8638da8fd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 19:55:46 +0000 Subject: [PATCH 5/6] Remove unused os import, make documentation consistently French Co-authored-by: hackolite <826027+hackolite@users.noreply.github.com> --- node/InputNode/spectrogram_utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/node/InputNode/spectrogram_utils.py b/node/InputNode/spectrogram_utils.py index 04f9fe66..722cef95 100644 --- a/node/InputNode/spectrogram_utils.py +++ b/node/InputNode/spectrogram_utils.py @@ -7,7 +7,6 @@ converting them to colored RGB images for better visualization and event detection. """ -import os import tempfile import cv2 import numpy as np @@ -248,11 +247,11 @@ def plot_spectrogram(location, plotpath=None, binsize=2**10, colormap="jet"): Returns: tuple: (ims, plotpath) where: - ims: Matrice du spectrogramme en décibels - - plotpath: Path to the saved spectrogram image (useful when temporary file is created) + - plotpath: Chemin vers l'image du spectrogramme sauvegardée Note: - When plotpath is None, a temporary file is created with delete=False. - The caller is responsible for cleaning up the temporary file if needed. + Quand plotpath est None, un fichier temporaire est créé avec delete=False. + L'appelant est responsable du nettoyage du fichier temporaire si nécessaire. """ if wav is None: raise ImportError("scipy is required for plot_spectrogram. Install with: pip install scipy") From 736913315e03aa2aaffaf8814f407242812f33e7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 19:56:30 +0000 Subject: [PATCH 6/6] Clarify documentation on temporary file cleanup responsibility Co-authored-by: hackolite <826027+hackolite@users.noreply.github.com> --- node/InputNode/spectrogram_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/node/InputNode/spectrogram_utils.py b/node/InputNode/spectrogram_utils.py index 722cef95..61365d37 100644 --- a/node/InputNode/spectrogram_utils.py +++ b/node/InputNode/spectrogram_utils.py @@ -251,7 +251,9 @@ def plot_spectrogram(location, plotpath=None, binsize=2**10, colormap="jet"): Note: Quand plotpath est None, un fichier temporaire est créé avec delete=False. - L'appelant est responsable du nettoyage du fichier temporaire si nécessaire. + Dans ce cas, l'appelant reçoit le chemin du fichier temporaire dans le tuple + de retour et est responsable de son nettoyage. Si plotpath est fourni par + l'appelant, aucun nettoyage n'est nécessaire de la part de cette fonction. """ if wav is None: raise ImportError("scipy is required for plot_spectrogram. Install with: pip install scipy")