From 2a3701f91c86050983264239117f903edbe15f27 Mon Sep 17 00:00:00 2001 From: Keyvan Hardani <Hardani@hotmail.de> Date: Wed, 24 Apr 2024 16:15:14 +0200 Subject: [PATCH] Update base_device.py Remove the temporary directory and its contents to free up disk space --- software/source/clients/base_device.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/software/source/clients/base_device.py b/software/source/clients/base_device.py index 3bf900e..d67bcc2 100644 --- a/software/source/clients/base_device.py +++ b/software/source/clients/base_device.py @@ -169,7 +169,7 @@ class Device: global RECORDING # Create a temporary WAV file to store the audio data - temp_dir = tempfile.gettempdir() + temp_dir = tempfile.mkdtemp(prefix="audio_") wav_path = os.path.join( temp_dir, f"audio_{datetime.now().strftime('%Y%m%d%H%M%S%f')}.wav" ) @@ -237,9 +237,8 @@ class Device: "end": True, } ) - - if os.path.exists(wav_path): - os.remove(wav_path) + # Remove the temporary directory and its contents + shutil.rmtree(temp_dir) def toggle_recording(self, state): """Toggle the recording state."""