所以我只是想知道如何才能播放两次持续1秒钟的蜂鸣声,两次蜂鸣之间有1秒钟的延迟。当我尝试import time
然后在我的两个函数调用中添加一个time.sleep(1)
时,它似乎不起作用
`play_beep()`
`time.sleep(1)`
`play_beep()`
#Function plays a 1 second beep
def play_beep():
CHUNK = 1024
if len(sys.argv) < 2:
print("Plays a wave file.\n\nUsage: %s filename.wav" % sys.argv[0])
sys.exit(-1)
wf = wave.open(sys.argv[1], 'rb')
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
data = wf.readframes(CHUNK)
while data != '':
stream.write(data)
data = wf.readframes(CHUNK)
stream.stop_stream()
stream.close()
p.terminate()
play_beep()
我们将不胜感激。无论如何解决这个问题都很棒!