Speech To Text code import speech_recognition as sr r = sr.Recognizer() with sr.Microphone() as source: print ( "Speak Anything :" ) audio = r.listen(source) try : text = r.recognize_google(audio) print ( "You said : {} " .format(text)) except : print ( "Sorry could not recognize what you said" )
Text To Voice Using Python code mport pyttsx3 import datetime engine = pyttsx3.init( 'sapi5' ) voices = engine.getProperty( 'voices' ) engine.setProperty( 'voices' , voices[ 0 ].id) def speak ( audio ): engine.say(audio) engine.runAndWait() def wishme (): hour = int (datetime.datetime.now().hour) if hour>= 0 and hour< 12 : speak( "good morning" ) elif hour>= 12 and hour<= 18 : speak( "good afternoon" ) else : speak( "good evening" ) speak( "hi mehul i am your assistant. how are you" ) a= input () if a == "i am fine" : speak( "it's good that you are fine " ) if __name__ == "__main__" : wishme()
Comments
Post a Comment