这是我的代码:
import pyttsx3
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices[0].id)
engine.setProperty('voice',voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
if __name__=="__main__":
speak("hello world")
注意:我已经安装了pyttsx3模块
错误:
[Running] python -u "f:jarvisjarvis.py"
Traceback (most recent call last):
File "f:jarvisjarvis.py", line 3, in <module>
voices = engine.getproperty('voices')
AttributeError: 'Engine' object has no attribute 'getproperty'
[Done] exited with code=1 in 2.08 seconds
请帮帮我如何解决此问题?
Python标识符区分大小写。
您写道:
voices = engine.getProperty('voices')
这很好,并且与文档完全匹配。
您显示的诊断是针对某些不同的代码:
voices = engine.getproperty('voices') AttributeError: 'Engine' object has no attribute 'getproperty'
诊断正确。当是CCD_ 1属性时,发动机缺少CCD_ 2。这是两个不同的标识符。拼写正确,你的程序就会运行得更好。