100% found this document useful (1 vote)
468 views15 pages

Python Project Report

This Python code creates a voice-controlled virtual assistant named Alexa. Alexa uses speech recognition and text-to-speech to understand voice commands and respond verbally or via text. It can perform tasks like playing music, telling the time, searching Wikipedia, telling jokes, and opening web browsers and programs. The code runs continuously, allowing multiple commands until the user says "thank you" to exit. Overall, the program demonstrates using Python libraries to build an interactive voice assistant for hands-free tasks.

Uploaded by

Sakshi Sonavane
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
100% found this document useful (1 vote)
468 views15 pages

Python Project Report

This Python code creates a voice-controlled virtual assistant named Alexa. Alexa uses speech recognition and text-to-speech to understand voice commands and respond verbally or via text. It can perform tasks like playing music, telling the time, searching Wikipedia, telling jokes, and opening web browsers and programs. The code runs continuously, allowing multiple commands until the user says "thank you" to exit. Overall, the program demonstrates using Python libraries to build an interactive voice assistant for hands-free tasks.

Uploaded by

Sakshi Sonavane
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 15

ALEXA

CONTENTS

SL. NO. PARTICULARS PAGE NO.


1 Abstratct 2
2 System Specifications 3
3 Introduction to VS Code 4
4 Implementation 5
5 Interaction 6
6 Source Code 7
7 Output 11
8 Conclusion 14
9 Bibliography 15

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.

VS Code features a streamlined user interface and a wide range of


extensions that allow developers to customize their workflow and enhance their productivity.
It supports various programming languages, including JavaScript, TypeScript, Python, C#,
and many others.

Some of the key features of VS Code include:


1. IntelliSense: VS Code's IntelliSense feature provides intelligent code completion,
syntax highlighting, and code snippets that help developers write code more quickly
and accurately.
2. Debugging: VS Code supports debugging for a wide range of programming
languages, allowing developers to quickly identify and fix issues in their code.
3. Source control: VS Code integrates with popular source control systems such as Git,
making it easy to manage code changes and collaborate with other developers.
4. Extensions: VS Code has a large library of extensions that allow developers to
customize their workflow and add new functionality to the editor.
5. Terminal integration: VS Code includes an integrated terminal that allows developers
to run commands and execute scripts without leaving the editor.

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

To implement the above code, follow the steps below:

1. Install the required libraries: speech_recognition, pyttsx3, pywhatkit, wikipedia,


pyjokes, subprocess
2. You can install these libraries using pip by running the following command in your
terminal:
“pip install speechrecognition pyttsx3 pywhatkit Wikipedia pyjokes ”
3. Copy the code into a Python file, for example, `alexa.py`.
4. Run the `alexa.py` file using a Python interpreter.
5. Once the program is running, say "Alexa" to activate the virtual assistant. You can
then give commands to Alexa, such as "play Despacito on YouTube" or "tell me a
joke".
6. Alexa will recognize and execute the command, and respond with either spoken
words or text output in the console.
7. You can continue giving commands to Alexa until you say "thank you" to end the
program.

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:

- "hi" to get a response of "Hello, How are you....?".


- "how are you" to get a response that Alexa is good and hopes the user is good too.
- "play" followed by a song name to play the song on YouTube using PyWhatKit
library.
- "time" to get the current time using datetime library.
- "who is" followed by a person's name to get a brief summary about the person from
Wikipedia using Wikipedia library.
- "date" to get a response that Alexa has a headache.
- "joke" to get a random joke using PyJokes library.
- "who made you" to get a response with the names of the developers who created the
program.
- "purpose" to get a response that the program was created for a college mini-project.
- "chrome" to open Google Chrome using the subprocess library.
- "youtube" to open YouTube in a web browser using the webbrowser library.
- "power toys" to open PowerToys using the subprocess library.
- "thank you" to get a response of "It's my pleasure, Have a Great Day".

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

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')
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

elif 'power toys' in command:


a='opening powertoys....'

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

Here is a possible bibliography for the code provided:


1. "Speech Recognition" - a Python library for performing speech recognition with
support for several engines, including Google Speech Recognition, Microsoft Bing
Voice Recognition, and others. Available at:
https://pypi.org/project/SpeechRecognition/
2. "pyttsx3" - a Python library for text-to-speech conversion. Available at:
https://pypi.org/project/pyttsx3/
3. "pywhatkit" - a Python library for performing several tasks with the help of various
APIs, such as playing songs on YouTube, opening web pages, etc. Available at:
https://pypi.org/project/pywhatkit/
4. "datetime" - a Python module for working with dates and times. Available at:
https://docs.python.org/3/library/datetime.html
5. "wikipedia" - a Python library for working with the Wikipedia API. Available at:
https://pypi.org/project/wikipedia/
6. "pyjokes" - a Python library for generating random jokes. Available at:
https://pypi.org/project/pyjokes/
7. "subprocess" - a Python module for working with system processes. Available at:
https://docs.python.org/3/library/subprocess.html
8. "webbrowser" - a Python module for opening web pages. Available at:
https://docs.python.org/3/library/webbrowser.html
In addition to these sources, the code may have also been inspired by various online tutorials,
code snippets, and examples found on websites such as Stack Overflow, GitHub, and others.
It is important to properly credit and cite any external sources used in a project report to
avoid plagiarism and give credit where it is due.

15

You might also like