Python 中 pyttsx3 和语音识别的分段错误错误

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

使用

pyttsx3
speech_recognition
运行 Python 脚本时遇到分段错误错误。这是我的代码的简化版本:

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}")

运行此脚本会导致“分段错误(核心转储)”错误。我该如何解决这个问题?

python segmentation-fault speech-recognition microphone pyttsx3
1个回答
0
投票

问题解决:问题在第 9 行

engine.say("")

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