在后台播放音频文件
play audio file in the background
我想使用 Pydub 库在后台播放音频文件(不阻塞我的其余代码)。
这是我到目前为止的代码,但它会等到音频结束,然后 运行 剩余的代码
sound = AudioSegment.from_wav('myfile.wav')
play(sound)
print("I like this line to be executed simoultinously with the audio playing")
在新线程中播放您的声音:
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")
我想使用 Pydub 库在后台播放音频文件(不阻塞我的其余代码)。 这是我到目前为止的代码,但它会等到音频结束,然后 运行 剩余的代码
sound = AudioSegment.from_wav('myfile.wav')
play(sound)
print("I like this line to be executed simoultinously with the audio playing")
在新线程中播放您的声音:
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")