diff --git a/main.py b/main.py new file mode 100644 index 0000000..6e3f469 --- /dev/null +++ b/main.py @@ -0,0 +1,77 @@ +# Copyright (c) 2020 PSMForums. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import speech_recognition as sr +import pyttsx3 +import pywhatkit +import datetime +import wikipedia +import pyjokes + + +listener = sr.Recognizer() +engine = pyttsx3.init() +voices = engine.getProperty('voices') +engine.setProperty('voice', voices[1].id) + + +def talk(text): + engine.say(text) + engine.runAndWait() + + +def take_command(): + r = sr.Recognizer() + with sr.Microphone() as source: + print("Listening...") + r.pause_threshold = 1 + audio = r.listen(source) + try: + print("Recognizing...") + command = r.recognize_google(audio, language='en-in') + print(f"User said: {command}\n") + + except Exception as e: + + print("Say that again please...") + return "None" + return command + + +if __name__ == "__main__": + + while True: + + command = take_command().lower() + + if 'play' in command: + song = command.replace('play', '') + talk('playing ' + song) + pywhatkit.playonyt(song) + elif 'time' in command: + time = datetime.datetime.now().strftime('%I:%M %p') + talk('Current time is ' + time) + elif 'wiki' in command: + search = command.replace('wiki', '') + info = wikipedia.summary(search, 1) + print(info) + talk(info) + elif 'date' in command: + talk('sorry, I have a headache') + elif 'are you single' in command: + talk('I am in a relationship with amazon') + elif 'joke' in command: + talk('Let me get you laughing') + talk(pyjokes.get_joke()) + elif 'stop' in command: + break + else: + talk('Please say the command again.') diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..b2a1b3e --- /dev/null +++ b/readme.md @@ -0,0 +1,47 @@ +# **Create your own virtual assistant with just a few lines code (Using only PYTHON)** + + +Hello & Welcome to this git page. Here I just created my own +virtual assistant with just a few lines of code. It is not an +issue if you are a beginner, or an advanced coder this way of +building your own virtual assistant is very simple and quick. + +The only major thing required from your side is the will to go +step by step with me and by the end of it you will have your own +virtual assistant up & running as a charm. + +To learn more about how I did it you can watch my YouTube +video on this or click here. + +### Pre-Requisites: +1. Python Interpreter (Like PyCharm) +2. Python Environment (Like Anaconda) +3. Basic knowledge of how Python works & computers work +4. A will to explore + +When all the above pre-requisites are there and ready you can +start to work on your own virtual assistant. Please follow each +and every step in order & if you have any error just go to the issues +to see if you find any issue that matches your which is already +resolved before opening an issues. + +## Steps: +1. Open PyCharm & create a new project with your virtual environment ready. +2. Open the terminal and paste the following in sequential order line by line(Execute it one by one): + +`pip install speechRecognistion` + +`pip install pyttsx3` + +`pip install pywhatkit` + +`pip install wikipedia` + +`pip install pyjokes` + +_Install this if necessary (Only when the code gives error)_ + +`pip install pyaudio` + +3. Copy the code given in main.py (in this git) & you will have the code up & running on your pc. +4. If you want to learn how this code actually works the go watch my YouTube video for a better understanding. \ No newline at end of file