1

Any ideas why the code below does not play the sound? If the s.play() were to be outside the clock() function, it work.

import time
import pygame

pygame.init()
s = pygame.mixer.Sound("0614.wav")

def clock ():
    x = input("How long to start the alarm for? ")
    delay = float(x)
    print ("Alarm Started")
    time.sleep(delay)
    print ("!!!!ALARM!!!!!")
    s.play()

clock()
Anubhav
  • 545
  • 3
  • 14
  • Check out [this answer](https://stackoverflow.com/a/23826081/6220679). Either replace `pygame.init()` with `pygame.mixer.init()` or open a pygame window: `screen = pygame.display.set_mode((width, height))`. You could also call `pygame.mixer.init()` before `pygame.init()`. – skrx Nov 05 '17 at 02:02

1 Answers1

0

Is your file "0614.wav" in the same folder as form the program is executed?.

To see the error use try-except block and then print the error.

  • Yes, same folder as the *.py file itself. Also the problem is I have no error. The code exits just fine and prints the "!!!ALARM!!!" line after the specified delay. Its just the sound that never plays. – Anubhav Nov 05 '17 at 00:47