import pyaudio
import wave
import time
def uptime(x):
x=time.perf_counter()
return x
#问题出现在这一部分
def main():
CHUNK = 1024
FILENAME = '1.wav'
wf = wave.open('1.wav', '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 = p.open(format=pyaudio.paInt16, channels=chan, rate=rate,
input=True, stream_callback=callback)
stream.stop_stream()
stream.close()
p.terminate()
return
i=0
while i<4:
t=time.perf_counter()
x=t
while uptime(x)<t+3:
x=time.perf_counter()
i=i+1
print(i)
main()
系统报错:
Traceback (most recent call last):
File "D:\python文件\自\计时器.py", line 41, in
main()
File "D:\python文件\自\计时器.py", line 21, in main
stream.write(data)
File "C:\Users\xlw\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyaudio.py", line 586, in write
exception_on_underflow)
KeyboardInterrupt