This is the code I have:
import winsound from myro import *
def main():
HftM1 = makeSong("REST 1; REST 1; REST 1; REST 1; REST 1; REST 1; REST 1; REST 1; D4 1/6; F4 1/6; D5 2/3; D4 1/6; F4 1/6; D5 2/3; E5 1/2; F5 1/6; E5 1/6; F5 1/6; E5 1/6; C5 1/6; A4 2/3; A4 1/3; D4 1/3; F4 1/6; G4 1/6; A4 1; A4 1/3; D4 1/3; F4 1/6; G4 1/6; E4 1; D4 1/6; F4 1/6; D5 2/3; E5 1/2; F5 1/6; E5 1/6; F5 1/6; E5 1/6; C5 1/6; A4 2/3; A4 1/3; D4 1/3; F4 1/6; G4 1/6; A4 2/3; A4 1/3; D4 1; REST 1; REST 1; REST 1")
saveSong(HftM1, "WindmillHut.txt", append=1)
song = readSong("WindmillHut.txt")
play = []
for n in range(len(song)):
play = song[n]
note = play[0]
duration = play[1]
winsound.Beep(int(note), int(duration*2000))
main()
When I try to run this, I keep getting the error:
Traceback (most recent call last):
File "C:/Users/Gerren.Kids-PC/Desktop/Gerren's Files/School/Programming 1/Mod 5/Code/WindmillHut.py", line 23, in -toplevel-
main()
File "C:/Users/Gerren.Kids-PC/Desktop/Gerren's Files/School/Programming 1/Mod 5/Code/WindmillHut.py", line 22, in main
winsound.Beep(int(note), int(duration*2000))
ValueError: frequency must be in 37 thru 32767
What am I doing wrong and what do I need to change it to? Please be specific.
the winsound.beep function is just a wrapper around the windows api beep function. the windows function requires the first parameter (the frequency), be between 37 and 32767. i suspect any frequency outside of the range is out of humans range of hearing. it could also be that way because the old sound cards that this function was meant for only supported that range.
you are calling winsound.beep() and whatever int(note) is returning is out of that range. you should check for note being valid before calling beep, probably.