Voice Assistant Report
Voice Assistant Report
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()
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
return wake_word.lower()
except Exception as e:
return ""
def takeCommand():
while True:
wake_word = listenForWakeWord()
if 'jarvis' in wake_word:
r = sr.Recognizer()
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
print("Recognizing command...")
return query.lower()
except Exception as e:
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:
while True:
query = takeCommand()
if 'wikipedia' in query:
speak('Searching Wikipedia...')
speak("According to Wikipedia")
print(results)
speak(results)
webbrowser.open("https://www.youtube.com")
webbrowser.open("https://www.google.com")
webbrowser.open("https://www.spotify.com")
playMusic(music_dir)
strTime = datetime.datetime.now().strftime("%H:%M:%S")