Add files via upload
This commit is contained in:
committed by
GitHub
parent
84558fc68a
commit
ef9eff7277
77
main.py
Normal file
77
main.py
Normal file
@@ -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.')
|
||||
Reference in New Issue
Block a user