-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.py
30 lines (23 loc) · 939 Bytes
/
play.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import pygame
# Initialize pygame mixer
pygame.mixer.init()
# Define the path to the folder containing audio files
folder_path = 'Jarvis/wav'
# Get a list of all files in the folder
audio_files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
# Filter out only the audio files (assuming .mp3 and .wav formats, you can add more)
audio_files = [f for f in audio_files if f.endswith('.mp3') or f.endswith('.wav')]
# Function to play an audio file
def play_audio(file_path):
pygame.mixer.music.load(file_path)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10) # Wait until the music finishes playing
# Iterate over each audio file and play it
for audio_file in audio_files:
full_path = os.path.join(folder_path, audio_file)
print(f"Playing {full_path}")
play_audio(full_path)
# Quit the mixer
pygame.mixer.quit()