How To Do Text To Speech With Python On A Toshiba Laptop And Windows 7?
Solution 1:
This error says that it can't find a executable of MPlayer since you just use a mplayer wrapper.
File".\program.py", line 1681, in playsound
player = mplayer.Player()
File"C:\Users\Student\Documents\notes\mplayer.py", line 109, in __init__
self.spawn()
File"C:\Users\Student\Documents\notes\mplayer.py", line 319, in spawn
close_fds=(not subprocess.mswindows))
File"C:\Python27\lib\subprocess.py", line 711, in __init__
errread, errwrite)
File"C:\Python27\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error2] The system cannot find the file specified
You can get a MPlayer binary from here: http://www.mplayerhq.hu/design7/dload.html
Most other python programs use ffmpeg and writing some wrapper scripts to play mp3 files.
Maybe you can get inspired by music-player
Also there is a page at the official Python site where you could find some libraries. https://wiki.python.org/moin/PythonInMusic But be ware, most of them are outdated.
The problem with pygame is, that you need to check if the music is playing and hold your program open as long as music is playing.
This could be done like this:
FRAMERATE = 30clock = pygame.time.Clock()
pygame.mixer.music.load(soundfile)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
clock.tick(FRAMERATE)
Edit: and to your bounty, there is not a really simple solution if you won't use pygame and the included sdl library. it's better to swap out py2exe / create your own "exe" without py2exe.
Solution 2:
You could try the mp3play
module for python. If it works for you, and works with py2exe
, then it's a very easy module to use. The docs page I like to says it needs win xp to run, but I use it successfully on win7
For example:
import mp3play
filename = r'C:\Documents and Settings\Michael\Desktop\music.mp3'
mp3 = mp3play.load(filename)
mp3.play()
# Let it play for up to 30 seconds, then stop it.import time
time.sleep(min(30, mp3.seconds()))
mp3.stop()
Check it out here
Solution 3:
As it happens I recently had an idea that led me to take another shot at this. This solution is extremely hackish and shouldn't be necessary but unfortunately it is. Basically what I do is open the file in windows media player but suppress the window using subprocess. I already have the basic answer at this question, so here it is because I don't much care to rewrite the exact same thing.
Post a Comment for "How To Do Text To Speech With Python On A Toshiba Laptop And Windows 7?"