Python Project Report
Python Project Report
CONTENTS
1
ALEXA
ABSTRACT
This Python code creates a virtual assistant named Alexa, which is capable of
performing various tasks through voice commands. The program uses libraries such as
speech_recognition, pyttsx3, pywhatkit, datetime, wikipedia, pyjokes, subprocess, and
webbrowser to recognize and execute commands.
The program begins by initializing the speech recognition module and the text-to-
speech engine. It then listens for user input through the microphone and uses the Google
Speech Recognition API to convert the speech into text. The user's commands are then
interpreted and executed through various functions.
The program's features include playing songs on YouTube, telling the current time,
searching for information on Wikipedia, telling jokes, opening web browsers, and launching
programs. It also includes responses to common questions, such as "Who made you?" and
"How are you?".
The program runs continuously in a while loop, allowing users to give multiple
commands. The loop ends when the user says "thank you", indicating that they are done using
the assistant.
Overall, this program demonstrates the use of Python libraries to build a voice-
controlled virtual assistant that can perform various tasks, making it a useful tool for those
who prefer voice-based interactions.
2
ALEXA
SYSTEM SPECIFICATIONS
Software Requirements :
Language : PYTHON
Integrated Development Environment (IDE) : VS CODE
Hardware Requirements :
Graphics System
Intel core i5 with 16 GB RAM
3
ALEXA
INTRODUCTION TO VS CODE
Visual Studio Code (VS Code) is a free and open-source code editor
developed by Microsoft. It is a lightweight yet powerful tool that is widely used by
developers for building web applications, desktop applications, and other software projects.
Overall, VS Code is a powerful and flexible code editor that is suitable for a wide range of
programming tasks. Its intuitive interface and powerful features make it a popular choice
among developers.
4
ALEXA
IMPLEMENTATION
Note: Make sure to test the program in a quiet environment and adjust the microphone
volume and settings as necessary for optimal performance. Also, note that some commands
may require an internet connection to work, such as searching on Wikipedia or opening web
browsers.
5
ALEXA
INTERACTIONS
The interaction commands in this program are voice commands that can be given to Alexa,
which are recognized by the program using the SpeechRecognition library. The following
commands are recognized by the program:
6
ALEXA
SOURCE CODE
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
import subprocess
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:
7
ALEXA
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 'date' in command:
talk('sorry, I have a headache but I am everywhere with you')
elif 'are you single' in command:
talk('I am in a relationship with Wifi')
elif 'joke' in command:
joke=pyjokes.get_joke()
8
ALEXA
print(joke)
talk(joke)
elif 'kiss' in command:
talk('I can but I am a Virtual Assistant')
elif 'how are you' in command:
talk('I am Good, Hope so as you are')
elif 'hi' in command:
talk('Hello, How are you....?')
elif 'who made you' in command:
talk('Sakshi Sonavane and Tejas Gupta')
elif 'purpose' in command:
talk('for their college mini project')
elif 'thank you' in command:
talk('Its my pleasure, Have a Great Day')
return False
elif 'chrome' in command:
a='opening chrome....'
engine.say(a)
engine.runAndWait()
program="C:\Program Files\Google\Chrome\Application\chrome.exe"
subprocess.Popen([program])
subprocess.Popen([program])
elif 'youtube' in command:
a='opening youtube....'
engine.say(a)
engine.runAndWait()
url = "https://www.youtube.com/"
webbrowser.open(url)
9
ALEXA
engine.say(a)
engine.runAndWait()
program="C:\Program Files\PowerToys\PowerToys.exe"
subprocess.Popen([program])
else:
talk('please say it again')
return True
while True:
if not run_alexa():
break
10
ALEXA
OUTPUT
11
ALEXA
12
ALEXA
13
ALEXA
CONCLUSION
This code is a Python program that uses speech recognition to interpret voice
commands given to a virtual assistant named Alexa. The assistant can perform several tasks,
including playing songs on YouTube, telling the time, providing information on famous
people using Wikipedia, telling jokes, opening web browsers and specific programs such as
Google Chrome and PowerToys, and engaging in small talk with users.
The program uses various Python libraries such as speech_recognition, pyttsx3,
pywhatkit, wikipedia, pyjokes, subprocess, and webbrowser to enable these features.
Additionally, it uses datetime to get the current time.
This program can be used as a starting point for developing a more advanced virtual
assistant that can perform more complex tasks based on user input. It can also serve as a basic
framework for creating similar virtual assistants in other programming languages.
14
ALEXA
BIBLIOGRAPHY
15