When I use playsound library in Python and when I try to play the audio in mp3 format, my audio just a few moments before the end just stops. How can I fix this problem?
from playsound import playsound
word = input(">")
while 0<1:
if(word == "hello"):
playsound('greetings.mp3')
I've run into the same issue a couple of times recently when using the
playsound
module on Windows 10. I found that, when playing shorter (around 3 seconds) audio clips,playsound
cut the end of it despite the original audio being complete. I noticed two interesting aspects:One workaround I figured out seems to work perfectly to me: I added a simple
time.sleep(1)
right afterplaysound.playsound()
like this:Note that depending on the length of your audios, you might want to increase the waiting time from 1 second to a bit more.