Update base_device.py

Remove the temporary directory and its contents to free up disk space
pull/254/head
Keyvan Hardani 1 year ago committed by GitHub
parent 625f02c9ce
commit 2a3701f91c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -169,7 +169,7 @@ class Device:
global RECORDING global RECORDING
# Create a temporary WAV file to store the audio data # 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( wav_path = os.path.join(
temp_dir, f"audio_{datetime.now().strftime('%Y%m%d%H%M%S%f')}.wav" temp_dir, f"audio_{datetime.now().strftime('%Y%m%d%H%M%S%f')}.wav"
) )
@ -237,9 +237,8 @@ class Device:
"end": True, "end": True,
} }
) )
# Remove the temporary directory and its contents
if os.path.exists(wav_path): shutil.rmtree(temp_dir)
os.remove(wav_path)
def toggle_recording(self, state): def toggle_recording(self, state):
"""Toggle the recording state.""" """Toggle the recording state."""

Loading…
Cancel
Save