Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

code alexa in python

#remember that this code you can change the name from anything, my favorite is alexa is to jarvis
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():
    try:
        with sr.Microphone() as source:
            print("Listening UWU")
            voice = listener.listen(source)
            command = listener.recognize_google(voice)
            command = command.lower()
            if 'jarvis' 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("playing")
    elif 'time' in command:
        time = datetime.datetime.now().strftime("%I:%M:%S:%P")
        print(time)
        talk("current time is", + time)
    elif 'wikipedia' in command:
        search = command.replace('wikipedia', '')
        information = wikipedia.summary(search, 1)
        print(information)
        talk(information)
    elif 'joke' in command:
        talk(pyjokes.get_jokes())
    else:
        talk("please bear with me sir, could you repeat it again")
run_alexa()
 
PREVIOUS NEXT
Tagged: #code #alexa #python
ADD COMMENT
Topic
Name
5+2 =