Dogbot/barking.py

23 lines
485 B
Python

import pygame
import time
import random
# Initialize pygame mixer
pygame.mixer.init()
# Load the sound file
sound = pygame.mixer.Sound("bark5.wav")
try:
while True:
# Play the sound
sound.play()
# Wait for the sound to finish playing
time.sleep(sound.get_length())
# Wait for a random interval between plays, e.g., 2 to 5 seconds
time.sleep(random.randint(2, 5))
except KeyboardInterrupt:
print("Playback stopped by user.")