I\'m using eSpeak on Ubuntu and have a Python 2.7 script that prints and speaks a message:
import subprocess
text = \'Hello World.\'
print text
subprocess.ca
Use subprocess.check_output (new in python 2.7). It will suppress stdout and raise an exception if the command fails. (It actually returns the contents of stdout, so you can use that later in your program if you want.) Example:
import subprocess
try:
subprocess.check_output(['espeak', text])
except subprocess.CalledProcessError:
# Do something
You can also suppress stderr with:
subprocess.check_output(["espeak", text], stderr=subprocess.STDOUT)
For earlier than 2.7, use
import os
import subprocess
with open(os.devnull, 'w') as FNULL:
try:
subprocess._check_call(['espeak', text], stdout=FNULL)
except subprocess.CalledProcessError:
# Do something
Here, you can suppress stderr with
subprocess._check_call(['espeak', text], stdout=FNULL, stderr=FNULL)