From 715154526649eb4da50946146a02eca8b5180674 Mon Sep 17 00:00:00 2001 From: Gir0fa Date: Mon, 4 Aug 2025 15:34:13 -0600 Subject: [PATCH] If Statement Nesting Error The delete_file if statement was wrongly nested inside the sleep_during_playback if statement. Doug likely never encountered issues because he likely never didn't sleep (tongue twister right there) --- audio_player.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/audio_player.py b/audio_player.py index cc7a20e..30f741a 100644 --- a/audio_player.py +++ b/audio_player.py @@ -49,17 +49,17 @@ def play_audio(self, file_path, sleep_during_playback=True, delete_file=False, p # Sleep until file is done playing time.sleep(file_length) - # Delete the file - if delete_file: - # Stop Pygame so file can be deleted - # Note: this will stop the audio on other threads as well, so it's not good if you're playing multiple sounds at once - pygame.mixer.music.stop() - pygame.mixer.quit() - try: - os.remove(file_path) - print(f"Deleted the audio file.") - except PermissionError: - print(f"Couldn't remove {file_path} because it is being used by another process.") + # Delete the file + if delete_file: + # Stop Pygame so file can be deleted + # Note: this will stop the audio on other threads as well, so it's not good if you're playing multiple sounds at once + pygame.mixer.music.stop() + pygame.mixer.quit() + try: + os.remove(file_path) + print(f"Deleted the audio file.") + except PermissionError: + print(f"Couldn't remove {file_path} because it is being used by another process.") async def play_audio_async(self, file_path): """ @@ -142,4 +142,4 @@ async def async_audio_test(): # audio_manager.play_audio(WAV_FILEPATH, True, True) # print("Sleeping until next file") # time.sleep(3) - \ No newline at end of file +