【发布时间】:2021-10-26 02:40:01
【问题描述】:
当导入 pyttsx3 并使用 sapi5 时,正在引发错误 cannot import name 'COMError'。
文本中的代码:
import pyttsx3
import datetime
import comtypes.client as cc
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
#print (voices)
engine.setProperty('voice',voices[33].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishme():
hour = int(datetime.datetime.now().hour)
if hour >=0 and hour <12:
speak = ("Good Morning!")
elif hour >=12 and hour <18:
speak = ("Good afternoon!")
else:
speak = ("Good evening!")
speak = ("I am Ryuga better then siri how may I help you")
if __name__ == '__main__':
wishme()
图片中的代码:
这是错误:
/usr/local/bin/python3 /Users/sidd/Desktop/jarvis/Jarvis.py
Traceback (most recent call last):
File "/Users/sidd/Desktop/jarvis/Jarvis.py", line 3, in <module>
import comtypes.client as cc
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/comtypes/__init__.py", line 23, in <module>
from _ctypes import COMError
ImportError: cannot import name 'COMError'
【问题讨论】:
-
请不要将代码添加为图像。试图帮助您的人可能想要复制并粘贴它。
-
这是否回答了您的问题:stackoverflow.com/questions/37161560/… ?
标签: python artificial-intelligence voice-recognition voice pyttsx3