我正在尝试在我的 PyQt 应用程序中使用 sounddevice OutputStream 来播放声音。
我想要类似的东西
import sounddevice as sd
def callback(...):
#stuff that works with a "with" statement
class MyApp(QtWidgets.QMainWindow):
def __init__(self):
#stuff and buttons
def startSound(self):
#called by a button
self.streamInstance = sd.OutputStream(settings)
def stopSound(self):
#called by another button
self.streamInstance.close()
现在这不起作用,但如果我设置为:
with sd.OutputStream(settings):
#a loop
它可以工作,但我无法停止来自另一个功能的流,并且应用程序停止运行。
如果有人有解决方法或修复的想法,将不胜感激