Sandip Mishra
Sandip Mishra

Reputation: 11

Segmentation Fault Error with pyttsx3 and speech_recognition in Python

I'm encountering a segmentation fault error when running my Python script with pyttsx3 and speech_recognition. Here's a simplified version of my code:

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

Running this script results in a "Segmentation fault (core dumped)" error. How can I resolve this issue?

Upvotes: 0

Views: 71

Answers (1)

Sandip Mishra
Sandip Mishra

Reputation: 11

Problem Solve : Problem was in 9 line

engine.say("")

Upvotes: 0

Related Questions