所以我的代码是这样的:
import winsound
import time
length = 250
class Notes():
def frequency(halfNotesFromA4):
value = 440 * ((2)**(1.0/12.0))**halfNotesFromA4
return (int)(value)
def processNote(note):
if(note == 'C'):return Notes.frequency(3)
if(note == 'D'):return Notes.frequency(5)
if(note == 'E'):return Notes.frequency(7)
if(note == 'F'):return Notes.frequency(8)
if(note == 'G'):return Notes.frequency(10)
if(note == 'A'):return Notes.frequency(12)
if(note == 'B'):return Notes.frequency(14)
song = "EDCDEEE"
noteList = list(song)
print(noteList)
for note in noteList:
print("Doing ", note)
frequency = Notes.processNote(note)
winsound.Beep(frequency, length)
它工作正常,但我遇到的问题是每次哔哔声之间都有暂停。我希望能不间断地连续播放声音,让它听起来像真正的音乐。winsound.Beep() 库可以做到这一点吗?