0% found this document useful (0 votes)
11 views4 pages

Voice Assistant Report

Uploaded by

Mihir Tabiyar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Voice Assistant Report

Uploaded by

Mihir Tabiyar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Development of a Voice Assistant Using Python

Abstract:
This report presents the design and implementation of a voice
assistant using Python. The assistant leverages
various Python libraries such as `pyttsx3` for text-to-speech
conversion, `speech_recognition` for voice input
processing, and `pygame` for playing media. The system is
capable of performing tasks such as opening applications,
fetching real-time information from the web, setting reminders,
and interacting with users through voice commands.

1. Introduction
Voice assistants have revolutionized human-computer
interaction, offering hands-free operation for various tasks.
This project explores the development of a voice assistant using
Python, providing functionalities such as task
automation, web browsing, and personal assistance.

2. Implementation
The following Python code demonstrates the working of the voice
assistant:

import pyttsx3

import speech_recognition as sr
import datetime

import wikipedia

import webbrowser

import os

import random

import pygame

engine = pyttsx3.init('sapi5')

voices = engine.getProperty('voices')

engine.setProperty('voice', voices[0].id)

def speak(audio):

engine.say(audio)

engine.runAndWait()

def listenForWakeWord():

r = sr.Recognizer()

with sr.Microphone() as source:

print("Listening for wake word...")

r.adjust_for_ambient_noise(source)

audio = r.listen(source)

try:

print("Recognizing wake word...")

wake_word = r.recognize_google(audio, language='en-in')

print(f"Wake word detected: {wake_word}")

return wake_word.lower()

except Exception as e:

print("No wake word detected...")

return ""

def takeCommand():
while True:

wake_word = listenForWakeWord()

if 'jarvis' in wake_word:

speak("Yes sir, how can I assist you?")

r = sr.Recognizer()

with sr.Microphone() as source:

print("Listening for command...")

r.adjust_for_ambient_noise(source)

audio = r.listen(source)

try:

print("Recognizing command...")

query = r.recognize_google(audio, language='en-in')

print(f"User said: {query}\n")

return query.lower()

except Exception as e:

print("Say that again please...")

continue

def playMusic(music_dir):

songs = os.listdir(music_dir)

if songs:

random_song = random.choice(songs)

print(f"Playing {random_song}...")

pygame.mixer.init()

pygame.mixer.music.load(os.path.join(music_dir, random_song))

pygame.mixer.music.play()

while pygame.mixer.music.get_busy():

continue

else:

print("No music files found in the directory.")


if __name__ == "__main__":

speak("I am Jarvis. Please tell me how may I help you")

while True:

query = takeCommand()

if 'wikipedia' in query:

speak('Searching Wikipedia...')

query = query.replace("wikipedia", "")

results = wikipedia.summary(query, sentences=2)

speak("According to Wikipedia")

print(results)

speak(results)

elif 'open youtube' in query:

webbrowser.open("https://www.youtube.com")

elif 'open google' in query:

webbrowser.open("https://www.google.com")

elif 'open spotify' in query:

webbrowser.open("https://www.spotify.com")

elif 'play music' in query:

music_dir = "C:\Users\mihir\Desktop\music" # Update with correct path

playMusic(music_dir)

elif 'time' in query:

strTime = datetime.datetime.now().strftime("%H:%M:%S")

speak(f"Sir, the time is {strTime}")

You might also like