- 14 Ocak 2021
- 976
- 264
Alıntı deildir
Python:
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
import webbrowser
listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for ses in engine.getProperty("voices"):
print(ses)
engine.setProperty('voice', voices[0].id)
def talk(text):
engine.say(text)
engine.runAndWait()
def take_command():
try:
with sr.Microphone() as source:
print('listening...')
talk("I am listening you")
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'alexa' in command:
command = command.replace('alexa', '')
print(command)
except:
pass
return command
def run_alexa():
command = take_command()
print(command)
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')
print(time)
talk('Current time is ' + time)
elif 'who is ' in command:
person = command.replace('who is', '')
info = wikipedia.summary(person, 1)
print(info)
talk(info)
elif 'are you single' in command:
talk('I am in a relationship with wifi')
elif 'joke' in command:
joke = pyjokes.get_joke()
print(joke)
talk(joke)
elif 'google search' in command:
command = command.replace("google search", "")
talk("I am opening google")
url = "https://www.google.com.tr/search?q=" + command
print(url)
webbrowser.open_new_tab(url)
elif command == "sorry":
talk("No problem.")
elif "thank you" or "thanks" in command:
talk("You're welcome.")
else:
talk('Please say the command again.')
while True:
run_alexa()