当我使用 pyttsx3 和 Speech_recognition 运行 Python 脚本时,我遇到了分段错误。这是我的代码的简化版本:import timeimport pyttsx3import Speech_recog...
和 pyttsx3
运行 Python 脚本时,我遇到了分段错误 speech_recognition
。这是我的代码的简化版本:
import time
import pyttsx3
import speech_recognition as sr
recognizer = sr.Recognizer()
engine = pyttsx3.init()
def speke(text):
engine.say("")
engine.say(text)
engine.runAndWait()
def dot_s():
for i in range(4):
time.sleep(0.5)
print(".", end="", flush=True)
print("")
if __name__ == "__main__":
speke("Initialize Jarvis......")
while True:
try:
with sr.Microphone() as source:
print("\nListening", end="", flush=True)
dot_s()
audio = recognizer.listen(source, timeout=2, phrase_time_limit=2)
print("Recognizing", end="", flush=True)
dot_s()
Word = recognizer.recognize_google(audio)
if Word.lower() == "jarvis":
speke("ya")
with sr.Microphone() as source:
print("\nJarvis Activating", end="", flush=True)
dot_s()
audio = recognizer.listen(source)
print("Recognizing", end="", flush=True)
dot_s()
command = recognizer.recognize_google(audio)
processCommand(command)
except Exception as x:
print(f"Error : {x}")
运行此脚本会导致“分段错误(核心转储)”错误。我该如何解决这个问题?
python3 main.py
Segmentation fault (core dumped)
这是 输出 (错误)