-1
import pyttsx3 as pyt
import datetime as DT
hour = int(DT.datetime.now().hour)
print(hour)

# enter code here

speak = pyt.init()
voices = speak.getProperty('voices')
speak.setProperty('voice', voices[1].id)

if hour>= 0 and hour<12:
    speak("Good Morning Sir !")
elif hour >=0 and hour<12 and hour<18:
    speak("Good Afternoon Sir !") 
GeeTransit
  • 1,458
  • 9
  • 22

1 Answers1

0

You'll want to call speak.say instead of just speak like such:

if hour>= 0 and hour<12:
    speak.say("Good Morning Sir !")
elif hour >=0 and hour<12 and hour<18:
    speak.say("Good Afternoon Sir !") 

And also, you should rename speak to engine to be more descriptive. Here's an example from the docs:

import pyttsx3
engine = pyttsx3.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
GeeTransit
  • 1,458
  • 9
  • 22