While Mac OSX has the say command to speak, or so

2019-09-05 05:32发布

问题:

While Mac OSX 10.11.5 (El Capitan) has the "say" command to speak in a system generated voice, or so to say, is there any command that is similar for Python that can be used in Python? If Subprocess is utilized, please explain on how to use that.

回答1:

You can use subprocess as follows:

import subprocess

my_message = "hello there"
subprocess.call(["say", my_message])


回答2:

PyTTSx package will help you with this. PyTTSx is a Python package supporting common text-to-speech engines on Mac OSX, Windows, and Linux.
Speaking text

import pyttsx
engine = pyttsx.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()


See more examples here



回答3:

Thank you everyone for the quick replies. I have been playing with the subprocess module, and I have gotten this to work:import subprocess m=subprocess.Popen(["say","hello"]) print(m) The .Popen command is also a quick way to get this to work. However, this is only working on my Mac and I need it to work on my Raspberry Pi for an interactive feature in my code. (I am using Pi Cam and Infrared Sensors for a robot that wheels around and when it senses people in front of it, says "Hey! Please move out of my way please!"