Make pyttsx3 wait more time

  alexa, python, pyttsx3

I’m making a virtual assistant project and when I say something and the command is done pyttsx3 is not waiting enough time to listen to the speech I’m saying

import pyttsx3
import speech_recognition as sr
import time

listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice' , voices[1].id)
rate = 160
engine.setProperty('rate', rate)
engine.say('Hi, im silica')
engine.say('How can I help you')
engine.runAndWait()


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 'silica' in command:
                command = command.replace('silica', '')
            time.sleep(1)


    except:
        pass
    return command

this is the code that I’m using.

Source: Python Questions

LEAVE A COMMENT