gpt4 book ai didi

Macintosh 中的 Python 文本转语音

转载 作者:太空狗 更新时间:2023-10-29 20:32:19 24 4
gpt4 key购买 nike

Python 中是否有任何库可以或允许使用 Mac Lion 的内置文本到语音引擎进行文本到语音转换?我没有谷歌,但大多数是基于 Windows 的。我试过pyttx。我试着跑了

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

如何解决这些错误?

最佳答案

这样做不是更简单吗?

from os import system
system('say Hello world!')

您可以输入 man say 以查看可以使用 say 命令执行的其他操作。

但是,如果您想要一些更高级的功能,也可以导入 AppKit,尽管需要一些 Cocoa/Objective C 知识。

from AppKit import NSSpeechSynthesizer
speechSynthesizer = NSSpeechSynthesizer.alloc().initWithVoice_("com.apple.speech.synthesis.voice.Bruce")
speechSynthesizer.startSpeakingString_('Hi! Nice to meet you!')

如果您想了解使用 NSSpeechSynthesizer 可以做的更多事情,请查看 Apple 的文档:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSSpeechSynthesizer_Class/Reference/Reference.html

关于Macintosh 中的 Python 文本转语音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12758591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com