Python在单独的线程中执行播放声音 [英] Python execute playsound in separate thread
本文介绍了Python在单独的线程中执行播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的 python 程序中播放声音,以便我使用 playsound 模块.
I need to play sound in my python program so that i used playsound module for that.
def playy():
playsound('beep.mp3')
如何修改它以在 main 方法中作为新线程运行.如果条件为真,我需要在主方法中运行此方法.当它为假时,线程需要停止
How can I modify this to run inside main method as a new thread. I need to run this method inside the main method if a condition is true.when it is false thread need to stop
推荐答案
使用线程库:
from threading import Thread
T = Thread(target=playy) # create thread
T.start() # Launch created thread
这篇关于Python在单独的线程中执行播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文