| | |
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
abrupt ansi anti apache approximation array basic beginner book builtin calculator chmod code converter countpasswordentry curved dan08 dictionaries dictionary dynamic examples excel file filename float format ftp function gui heads homework import inches input java launcher library line lines linux list lists loop mouse mysql mysqlquery newb number numbers numeric output parsing path phonebook plugin port prime program programming progressbar projects py2exe pygame pyqt pysimplewizard python random recursion recursive redirect scrolledtext server software ssh stamp statictext statistics string strings table terminal text textarea thread threading time tkinter tlapse trick tuple tutorial twoup ubuntu unicode urllib urllib2 variable windows wordgame wxpython



