While Mac OSX has the say command to speak, or so to say, is there any command that is similar for Python?

无人久伴 提交于 2019-12-12 01:57:36

问题


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!"



来源:https://stackoverflow.com/questions/38387676/while-mac-osx-has-the-say-command-to-speak-or-so-to-say-is-there-any-command-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!