在语音辅助代码中,isp5 似乎是一个关键错误,这是否有原因?

问题描述 投票:0回答:1

我是Python初学者,想写一个简单的语音助手。我想测试代码,但出现错误。 代码:



import subprocess

import wolframalpha

import pyttsx3

import tkinter

import json

import random

import operator

import speech_recognition as sr

import datetime

import wikipedia

import webbrowser

import os

import pyjokes

import feedparser

import smtplib

import ctypes

import time

import requests

import shutil

from twilio.rest import Client

from clint.textui import progress

from ecapture import ecapture as ec

from bs4 import BeautifulSoup

engine = pyttsx3.init('sapi5')

voices = engine.getProperty('voices')

engine.setProperty('voice', voices[1].id)

#defining functions

def speak(audio) :

 engine.say(audio)

 engine.runAndWait()

 

def wishMe():

 hour = init(datetime.datetime.now().hour)

 if hour>= 0 and hour <12:

    speak('Good Morning Sir !')

 elif hour>= 12 and hour<18:

    speak('Good Afternoon Sir!')

 else:

    speak('Good Evening Sir!')

 assname = (' Beta Liar 1 point 0')

 speak('I am your assistent')

 speak(assname)

def username():

 speak('What should i call you master')

 uname = takeCommand()

 speak('Welcome Master')

 speak(uname)

 columns = shutil.get_terminal_size().columns

 

 print('###############'.center(columns))

 print('Welcome Master.', uname.center(columns))

 print('###############'.center(columns))

 

 speak('How can i Help you, Master')

 

def takeCommand():

  r = sr.Recognizer()

 

  with sr.Microphone() as source:

      print('Listening...')

      r.pause_threshold = 1

      audio = r.listen(source)

  try:

     print('Recognizing...')

     query = r.recognize_google(audio, language = 'en-in')

     print(f"User said: {query}\n")

  except Exception as e:

     print(e)

     print('Unable to Recognize your Voice.')

     return 'None'

  return query

 

# Main Function

if __name__ == 'main':

   clear = lambda: os.system('clear')

   

   

   clear()

   wishMe()

   username()          

     

现在如您所见,这是一个非常初学者的代码。哈哈... 所以错误如下:



Traceback (most recent call last):

  File "/usr/local/lib/python3.11/dist-packages/pyttsx3/__init__.py", line 20, in init

    eng = _activeEngines[driverName]

          ~~~~~~~~~~~~~~^^^^^^^^^^^^

  File "/usr/lib/python3.11/weakref.py", line 136, in __getitem__

    o = self.data[key]()

        ~~~~~~~~~^^^^^

KeyError: 'sapi5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/home/kali/Desktop/Python/liar.py", line 30, in <module>

    engine = pyttsx3.init('sapi5')

             ^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/dist-packages/pyttsx3/__init__.py", line 22, in init

    eng = Engine(driverName, debug)

          ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/dist-packages/pyttsx3/engine.py", line 30, in __init__

    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)

                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/dist-packages/pyttsx3/driver.py", line 50, in __init__

    self._module = importlib.import_module(name)

                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import

  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load

  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 940, in exec_module

  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed

  File "/usr/local/lib/python3.11/dist-packages/pyttsx3/drivers/sapi5.py", line 1, in <module>

    import comtypes.client  # Importing comtypes.client will make the gen subpackage

    ^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/dist-packages/comtypes/__init__.py", line 28, in <module>

    from _ctypes import COMError

ImportError: cannot import name 'COMError' from '_ctypes' (/usr/lib/python3.11/lib-dynload/_ctypes.cpython-311-x86_64-linux-gnu.so)

所以关键错误似乎是 sapi5。我认为这是模块的问题...

所以我尝试使用 pip 重新安装 pyttsx3 和 comtypes 模块。但它出现了同样的错误...也许它与Python3不兼容?我不知道了,也许你可以帮助我。我在 Windows 上使用 Kali Linux VM 和主机

python virtual-machine speech-recognition
1个回答
0
投票

Bilo bagge bile da ki karegi vadde vadde boliya di karegi

© www.soinside.com 2019 - 2024. All rights reserved.