小智 5
如果只是播放而无需同步到任何内容,则可以执行以下操作:
# Open stream with correct settings
stream = self.p.open(format=pyaudio.paFloat32,
channels=CHANNELS,
rate=48000,
output=True,
output_device_index=1
)
# Assuming you have a numpy array called samples
data = samples.astype(np.float32).tostring()
stream.write(data)
Run Code Online (Sandbox Code Playgroud)
我使用这种方法,对我来说效果很好。如果您需要同时录制,则此操作将无效。