pyAudio在写入流时冻结

时间:2018-11-16 20:50:23

标签: raspberry-pi pyaudio

我正在使用以下代码播放通过UDP数据包接收的音频,并且在Windows 10上运行时一切正常,但是在具有USB扬声器的Raspberry Pi 3b +上运行时,脚本将挂在stream.write()之后。几包。有谁知道是什么原因造成的?

import pyaudio
import socket

FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
CHUNK = 4096

udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp.bind(("0.0.0.0", 5001))

audio = pyaudio.PyAudio()
stream = audio.open(format=FORMAT, channels=CHANNELS, rate=RATE, output=True, frames_per_buffer=CHUNK)

try:
    while True:
        data, addr = udp.recvfrom(CHUNK * CHANNELS * 2)
        stream.write(data)

except KeyboardInterrupt:
    pass

udp.close()
stream.close()
audio.terminate()

0 个答案:

没有答案