From 6753d81627d4467e649a6bb8dcb44c7eb8e42e1e Mon Sep 17 00:00:00 2001 From: yum Date: Fri, 1 Sep 2023 01:06:44 -0700 Subject: Various cleanup --- Sounds/aiueo/play.py | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 Sounds/aiueo/play.py (limited to 'Sounds') diff --git a/Sounds/aiueo/play.py b/Sounds/aiueo/play.py deleted file mode 100644 index 674cf2e..0000000 --- a/Sounds/aiueo/play.py +++ /dev/null @@ -1,40 +0,0 @@ -import winsound -import os -import random -import time - -def get_wav_files_in_cwd(): - """Returns a list of .wav files in the current working directory.""" - cwd = os.path.dirname(os.path.abspath(__file__)) - return [os.path.join(cwd, f) for f in os.listdir(cwd) if f.endswith('.wav')] - -# Pro tip: wrap this in a predicate -def play_random_wav(wav_files): - """Plays a random .wav file from the provided list asynchronously.""" - random_file = random.choice(wav_files) - winsound.PlaySound(random_file, winsound.SND_FILENAME | winsound.SND_ASYNC) - -def probably_play_random_wav(wav_files): - """Plays a random .wav file from the list. Probably.""" - if random.randint(1,3) == 1: - play_random_wav(wav_files) - -def main(): - wav_files = get_wav_files_in_cwd() - for file in wav_files: - print(f"file get: {file}") - if not wav_files: - print("No .wav files found in the current directory.") - return - - try: - while True: - probably_play_random_wav(wav_files) - time.sleep(0.04) - except KeyboardInterrupt: - print("Program terminated by user.") - winsound.PlaySound(None, winsound.SND_PURGE) # Stop any ongoing asynchronous sounds - -if __name__ == "__main__": - main() - -- cgit v1.2.3