Search
 
SCRIPT & CODE EXAMPLE
 

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()
Comment

PREVIOUS NEXT
Code Example
Python :: sort key python 
Python :: how to create a calculator in python 
Python :: silent plt.plot 
Python :: 1038 solution python 
Python :: rename column in dataframe 
Python :: set application taskbar icon 
Python :: python empty array length n grepper 
Python :: correct code to read csv file in python 
Python :: how to add import pydictionary in python 
Python :: python second max in numpy array 
Python :: pandas melt and stack 
Python :: what is quit block in python 
Python :: 1046 uri solution 
Python :: The simplest way to start using doctest in python 
Python :: accessing list python 
Python :: hide model field form 
Python :: python threadpool map exception 
Python :: python os path join list 
Python :: Python Tkinter Canvas Widget Syntax 
Python :: difference() Function of sets in python 
Python :: Calculate summary statistics across columns 
Python :: How to join or combine multiple csv files with concatenate and export dataframe to csv format 
Python :: How to convert string to uppercase, lowercase and how to swapcase in python 
Python :: django url wildcard 
Python :: airflow get execution context dictionary kubernetes pod name 
Python :: how to find most occurring items in sequence python 
Python :: python advanced programs time 
Python :: geodataframe and geoseries 
Python :: spark sparsevector to list 
Python :: python array_combine 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =