Skip to content

Instantly share code, notes, and snippets.

@RemmyDev1
Created March 31, 2023 01:26
Show Gist options
  • Save RemmyDev1/029192f034a14d541ee07eff8fcb5d0b to your computer and use it in GitHub Desktop.
Save RemmyDev1/029192f034a14d541ee07eff8fcb5d0b to your computer and use it in GitHub Desktop.
my alexa
import speech_recognition as sr
sr.__version__
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
import webbrowser
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():
try:
with sr.Microphone() as source:
print('listening...')
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')
talk('Current time is ' + time)
elif 'who is' in command:
person = command.replace('who the heck is', '')
info = wikipedia.summary(person, 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 google')
elif 'joke' in command:
talk(pyjokes.get_joke())
elif 'open google' in command:
url ='https://www.google.com/'
webbrowser.open(url)
talk('opening google')
elif 'open youtube' in command:
url ='https://www.youtube.com/'
webbrowser.open(url)
talk('opening youtube')
elif 'open github' in command:
url ='https://www.github.com/'
webbrowser.open(url)
talk('opening github')
elif 'open unity' in command:
url ='https://assetstore.unity.com/'
webbrowser.open(url)
talk('opening unity')
else:
talk('Please say the command again.')
while True:
run_alexa()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment