I have a clock I made and I'd like to make it an alarm clock.
+4
A:
Assuming you're on Windows:
import winsound
winsound.PlaySound('alert.wav')
If you're on Linux (or Mac OS X I believe), you can either use pygame or call a Linux program (like mplayer) using popen
. pygame example:
import pygame
pygame.init()
pygame.mixer.music.load("alert.ogg")
pygame.mixer.music.play()
pygame.event.wait()
Example using popen
, which executes a command as if you were in the terminal:
from os import popen
cmd = "mplayer alert.ogg"
popen(cmd)
Rafe Kettler
2010-10-24 00:45:31
+1
A:
If you have the MP3Play module, and plan on playing an MP3 file, you can use this simple method.
import mp3play
filename = "C:/PATH/TO/FILE.mp3"
sound = mp3play.load(filename)
sound.play()
That code will play the entire MP# file until it is done. If you want to only play that sound for only a certain amount of time, use this:
import mp3play
import time
filename = "C:/PATH/TO/FILE.mp3"
sound = mp3play.load(filename)
time.sleep(min(30, sound.seconds())) #Plays the first 30 seconds of sound
sound.stop()
This module can be downloaded from:
http://pypi.python.org/pypi/mp3play/0.1.15#downloads
Zachary Brown
2010-10-24 02:59:14
A:
On Debian/Ubuntu try this:
sudo apt-get install beep
and then:
import os
os.system('beep')
Tomasz Zielinski
2010-10-24 09:25:24