简体   繁体   English

在后台播放音频文件

[英]play audio file in the background

I want to play an audio file in the background (without blocking the rest of my code) using Pydub library.我想使用 Pydub 库在后台播放音频文件(不阻止我的其余代码)。 Here is the code I have so far but it will wait till the audio finishes and then run the remaining of the code这是我到目前为止的代码,但它会等到音频结束,然后运行剩余的代码

sound = AudioSegment.from_wav('myfile.wav')
play(sound)
print("I like this line to be executed simoultinously with the audio playing")

Play your sound in a new thread:在新线程中播放您的声音:

from pydub import AudioSegment
from pydub.playback import play
import threading

sound = AudioSegment.from_wav('myfile.wav')
t = threading.Thread(target=play, args=(sound,))
t.start()

print("I like this line to be executed simoultinously with the audio playing")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM