简体   繁体   English

我无法运行 this.py 文件。 收到很多错误。 无法弄清楚发生了什么

[英]I am unable to run this .py file. Recieved many errors. Couldn't figure out what's happeneing

import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes

listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)


def talk(text):
  engine.say(text)
  engine.runAndWait()


 def take_command():
try:
    with sr.Microphone() as source:
        print('listening...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        command = command.lower()
        if 'cyther' in command:
            command = command.replace('cyther', '')
            print(command)
except:
    pass
return command


def run_alexa():
  command = take_command()
  print(command)
  if 'play' in command:
      song = command.replace('play', '')
      talk('playing ' + song)
      pywhatkit.playonyt(song)
elif 'time' in command:
    time = datetime.datetime.now().strftime('%I:%M %p')
    talk('Current time is ' + time)
elif 'who the heck is' in command:
    person = command.replace('who the heck is', '')
    info = wikipedia.summary(person, 1)
    print(info)
    talk(info)
elif 'date' in command:
    talk('sorry, I have a headache')
elif 'are you single' in command:
    talk('I am in a relationship with wifi')
elif 'joke' in command:
    talk(pyjokes.get_joke())
else:
    talk('Please say the command again.')


while True:
  run_alexa()

The Terminal Gave:终端给予:

C:\Users\Prakash\Desktop\romantic-alexa-main>C:/Users/Prakash/AppData/Local/Programs/Python/Python37/python.exe c:/Users/Prakash/Desktop/romantic-alexa-main/main.py
Traceback (most recent call last):
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\weakref.py", line 137, in __getitem__
    o = self.data[key]()
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module>
    from comtypes.gen import SpeechLib  # comtypes
ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\gen\__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 121, in WINFUNCTYPE
    return _win_functype_cache[(restype, argtypes, flags)]
KeyError: (<class 'ctypes.HRESULT'>, (<class 'comtypes.automation.tagVARIANT'>, <class 'ctypes.wintypes.LP_c_long'>), 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:/Users/Prakash/Desktop/romantic-alexa-main/main.py", line 9, in <module>
    engine = pyttsx3.init()
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
    self._module = importlib.import_module(name)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in <module>
    engine = comtypes.client.CreateObject("SAPI.SpVoice")
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
    return _manage(obj, clsid, interface=interface)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
    obj = GetBestInterface(obj)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\__init__.py", line 110, in GetBestInterface
    mod = GetModule(tlib)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\_generate.py", line 118, in GetModule
    mod = _CreateWrapper(tlib, pathname)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\_generate.py", line 198, in _CreateWrapper
    mod = _my_import(fullname)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\_generate.py", line 19, in _my_import
    return __import__(fullname, globals(), locals(), ['DUMMY'])
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\gen\_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 253, in <module>
    ( ['out', 'retval'], POINTER(VARIANT), 'NewPosition' )),
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\__init__.py", line 323, in __setattr__
    self._make_methods(value)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\__init__.py", line 692, in _make_methods
    prototype = WINFUNCTYPE(restype, *argtypes)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 123, in WINFUNCTYPE
    class WinFunctionType(_CFuncPtr):
TypeError: item 1 in _argtypes_ passes a union by value, which is unsupported.

Anyone know what's going on?有谁知道发生了什么? Just saw this project randomly and started to type the same.刚刚随机看到这个项目并开始输入相同的内容。 Imported all the modules required but I am stuck at this error.导入了所有需要的模块,但我遇到了这个错误。

one of the errors that you are doing here is:您在这里犯的错误之一是:

1st: you should use (for example in your code) if command == "cyther": do what ever you want in it this should be the format of all if and elif statements in your code(replace: if command in "Example": --> to if command == "Example": )第一个:你应该使用(例如在你的代码中) if command == "cyther":做任何你想做的事情这应该是你代码中所有 if 和 elif 语句的格式(替换: if command in "Example": --> to if command == "Example":

im not familiar with anything in run_alexa() function, but the thing stated above should fix most of your issues.我不熟悉run_alexa() function 中的任何内容,但上述内容应该可以解决您的大部分问题。

Hopefully this helped you, and feel free to ask any question regarding this:)希望这对您有所帮助,并随时提出有关此的任何问题:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在python中调用模块来处理同一个文件。 它适用于一种情况,但不适用于另一种情况,我无法弄清楚有什么不同 - Calling a module in python to process the same file. It works in one scenario, but not in the other, and I can't figure out what's different 当我运行它的 .py 文件时,无法在 python 中写入文件。 但是当我在pycharm中运行它时,它确实有效 - Can't write files in python when I run it's .py file. But when I run it in pycharm, it actually work Discord.py 欢迎程序不起作用,我没有收到任何错误。 如何解决? - Discord.py welcomer doesn't work and I don't receive any errors. How to solve it? 我正在使用 Python 制作一个简单的密码生成器,运行它时没有任何反应,但我也没有看到任何错误。 我做错了什么? - I am making a simple password generator using Python and nothing happens when I run it but I also see no errors. What did I do wrong? 运行代码时显示错误,我无法弄清楚第二个问题 - Error is being shown when I run the code and I am unable to figure out the second question 列出我无法弄清楚的 Python 中的问题 - List Problem in Python that I couldn't figure out 我无法弄清楚我在这里失败了哪些测试用例 - I'm unable to figure out what test cases am I failing here cassandra python“ item = val [i]”无法弄清楚 - cassandra python “ item = val[i] ” couldn't figure it out 我无法弄清楚“期望缩进块” - “expected an indented block” which I couldn't figure out 无法弄清楚成功运行我的 Django 项目缺少什么 - Unable to figure out what's missing to run my Django Project successfully
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM