File playing normaly in python shell. Same code in script not playing, but getting right duration. What is wrong?
>>> import mplayer
>>> p = mplayer.Player()
>>> p.loadfile('announce_vlad.wav')
Script:
import mplayer
p = mplayer.Player()
p.loadfile('announce_vlad.wav')
print p.length
print p.is_alive()
Script output:
5.955873
True
It seems that the player runs in the background, and stops as soon as your script exits. (In the Python shell, this won't normally be a problem, since the shell will stay open while waiting for your input.)
To keep the player from stopping prematurely, you'll need to somehow keep your script running until the player has finished. One way to do that, since you already know the duration of the clip you're playing, could be to just sleep()
for the duration.
(There might be better ways to do that, but alas, I'm not really familiar enough with mplayer to tell. You may want to check the mplayer documentation to see if there's some way to make the player wake your script up when it has finished playing.)