how to make your own alexa using python
import time
import speech_recognition as sr
import pyttsx3
import wikipedia
import pywhatkit
import screen_brightness_control as screen
while True:
try:
recognizer = sr.Recognizer()
microphone = sr.Microphone()
with microphone as source:
print("Speak now...")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
response = recognizer.recognize_google(audio).lower()
#print(response)
if "alexa" in response:
response1 = response.replace("alexa", "")
brightness = screen.get_brightness()
screen.set_brightness(10)
time.sleep(1)
screen.set_brightness(brightness)
print(response1)
if "play" in response1:
response1.replace("play","")
pywhatkit.playonyt(response)
if "time" in response1:
#pyttsx3.speak("Current time is",time.strftime("%H hours %M minutes"))
print(time.strftime("%H %M %S"))
if "set brightness to minimum" in response1:
screen.set_brightness(20)
if "set brightness to medium" in response1:
screen.set_brightness(50)
if "set brightness to maximum" in response1:
screen.set_brightness(100)
if "get brightness" in response1:
pyttsx3.speak("Current brightness is", screen.get_brightness())
print(screen.get_brightness())
if "search for" in response1:
response1.replace("search for","")
search_for = response1
Web_result = wikipedia.summary(search_for)
pyttsx3.speak(Web_result)
if "jokes" in response1:
pyttsx3.speak("I am for useful purpose only and also i am alexa not a joker who will tell you jokes")
except:
print("an error occurred")
#pyttsx3.speak("An error occurred")
# you can customize your alexa with more features