Python中是否有使用Mac Lion内置的文本到语音引擎进行文本到语音转换的库? 我做过谷歌,但大多数都是基于windows的。我试过派特克斯。 我试着跑
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()
但我有这些错误
File "/Users/manabchetia/Documents/Codes/Speech.py", line 2, in <module>
engine = pyttsx.init()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx-1.0.egg/pyttsx/__init__.py", line 39, in init
eng = Engine(driverName, debug)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx-1.0.egg/pyttsx/engine.py", line 45, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx-1.0.egg/pyttsx/driver.py", line 64, in __init__
self._module = __import__(name, globals(), locals(), [driverName])
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyttsx-1.0.egg/pyttsx/drivers/nsss.py", line 18, in <module>
ImportError: No module named Foundation
如何解决这些错误?
这样做不是简单得多吗?
您可以输入
man say
来查看使用say
命令可以执行的其他操作。然而,如果您想要一些更高级的特性,导入
AppKit
也是一种可能,尽管需要一些Cocoa/Objective C知识。如果您想了解更多关于NSSpeechSynthesizer的信息,请查看苹果的文档:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSSpeechSynthesizer_Class/Reference/Reference.html
如果你的目标是MacOSX作为你的平台——PyObjC和NSSpeechSynthesizer是你最好的选择。
下面是一个简单的例子
请注意,AppKit模块是PyObjC桥的一部分,应该已经安装在您的Mac上了。如果您使用的是操作系统提供的python(/usr/bin/python),则无需安装它
这可能有效:
相关问题 更多 >
编程相关推荐