标题说明了问题所在。我不知道如何解决这个问题。咔哒声在播放的每个音调之间。我也听起来像一些人的流行音乐。
import math
import pyaudio
import sys
PyAudio = pyaudio.PyAudio
def playTone(rate,wave,time,channel):
data = ''.join([chr(int(math.sin(x/((rate/wave)/math.pi))*127+128)) for x in xrange(rate)])
p = PyAudio()
stream = p.open(format =
p.get_format_from_width(1),
channels = channel,
rate = rate,
output = True)
for DISCARD in xrange(int(time)):
stream.write(data)
#stream.stop_stream()
#stream.close()
#p.terminate()
'''
playTone(88000,400,1,2)
playTone(88000,500,1,1)
playTone(88000,600,1,2)
playTone(88000,700,1,2)
'''
def scale(noteNumber):
counter = 100
while noteNumber*100 > counter:
playTone(88000,100+counter,1,2)
counter += 100
scale(10)