我想播放声音效果,但是在播放声音时继续执行脚本。 我正在使用“ playsound”播放音频 目前看来,子流程正是我所需要的
可能有更好的解决方案来解决这个问题
import subprocess
from playsound import playsound
subprocess.Popen(
playsound("audio.mp3")
)
#Code while audio is playing
答案 0 :(得分:0)
尝试使用线程。下面的示例:
from playsound import playsound
import threading
def play_music():
print 'Playing ....'
playsound('<Music file path>')
#create thread to play music
t1 = threading.Thread(target=play_music)
t1.start()
#your code
for i in range(0, 10):
print i
#wait for music to complete
t1.join()
print 'End'