| | |
Musical Beeps (Python)
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
If you have a Windows computer you can play musical beeps through the internal speaker. In this case it will sound like a very tiny Big Ben, brought to you by the module winsound and its method Beep().
# play music on the PC internal speaker # tested with Python24 on a Windows XP computer vegaseat 15aug2005 import winsound import time # the notes P = 0 # pause C = 1 CS = 2 # C sharp D = 3 DS = 4 E = 5 F = 6 FS = 7 G = 8 GS = 9 A = 10 AS = 11 B = 12 EN = 100 # eighth note QN = 200 # quarter note HN = 400 # half note FN = 800 # full note def play(octave, note, duration): """play note (C=1 to B=12), in octave (1-8), and duration (msec)""" if note == 0: # a pause time.sleep(duration/1000) return frequency = 32.7032 # C1 for k in range(0, octave): # compute C in given octave frequency *= 2 for k in range(0, note): # compute frequency of given note frequency *= 1.059463094 # 1.059463094 = 12th root of 2 time.sleep(0.010) # delay between keys winsound.Beep(int(frequency), duration) def bigben(): play(4,E,HN) play(4,C,HN) play(4,D,HN) play(3,G,HN+QN); play(3,P,QN) play(3,G,HN) play(4,D,HN) play(4,E,HN) play(4,C,HN+QN) bigben()
Similar Threads
- musical code (Assembly)
- Musical Taste (Geeks' Lounge)
- musical tones (C++)
- Musical freezing!!!!! (Windows NT / 2000 / XP)
| Thread Tools | Search this Thread |
Tag cloud for Python
alarm assignment avogadro beginner bluetooth character cmd code copy customdialog cx-freeze data decimals dictionary directory dynamic error examples excel exe file float format function generator gnu graphics gui halp homework http ideas import input itunes java leftmouse line linux list lists logging loop maze module mouse number numbers output parsing path port prime program programming projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh stdout string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode update urllib urllib2 variable ventrilo verify vigenere web webservice wikipedia windows wxpython xlib



