├── README.md └── main.py /README.md: -------------------------------------------------------------------------------- 1 | # Trinity-AI 2 | Python code for Voice assistance 3 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import speech_recognition as sr 2 | import pyttsx3 3 | import pywhatkit 4 | import datetime 5 | import wikipedia 6 | import pyjokes 7 | 8 | listener = sr.Recognizer() 9 | engine = pyttsx3.init() 10 | voices = engine.getProperty('voices') 11 | engine.setProperty('voice', voices[1].id) 12 | 13 | 14 | def talk(text): 15 | engine.say(text) 16 | engine.runAndWait() 17 | 18 | 19 | def take_command(): 20 | try: 21 | command = '' 22 | with sr.Microphone() as source: 23 | print('listening...') 24 | voice = listener.listen(source) 25 | command = listener.recognize_google(voice) 26 | command = command.lower() 27 | 28 | except: 29 | pass 30 | return command 31 | 32 | 33 | def run_trinity(): 34 | command = take_command() 35 | print(command) 36 | if 'play' in command: 37 | song = command.replace('play', '') 38 | talk('playing ' + song) 39 | pywhatkit.playonyt(song) 40 | elif 'time' in command: 41 | time = datetime.datetime.now().strftime('%I:%M %p') 42 | talk('Current time is ' + time) 43 | elif 'search for' or 'who is' in command: 44 | person = command.replace('search for', '') 45 | info = wikipedia.summary(person, 1) 46 | print(info) 47 | talk(info) 48 | elif 'joke' in command: 49 | talk(pyjokes.get_joke()) 50 | elif 'what is your name' in command: 51 | talk('I am trinity') 52 | print('I am trinity') 53 | elif 'who are you' in command: 54 | talk('i am trinity an AI') 55 | elif 'hello trinity' in command: 56 | talk('at your service sir') 57 | elif'what' in command: 58 | talk('I will make your work easy') 59 | else: 60 | talk('Please say the command again.') 61 | 62 | 63 | while True: 64 | run_trinity() --------------------------------------------------------------------------------