Department of Electronics & Telecommunications Engineering
Mini Project Report
On
Title: - Voice Assistant — Speech-based Personal Assistant
with TTS, News, Music & AI
Student Sap IDs and Names: -
1. Parshva Panchal - 60002240027
2. Keerthi Pai - 60002240215
3. Preet Pancholi - 60002240249
4. Saman Panchal - 60002240043
Course Instructor: - Mr. Tushar Sawant
Department of Electronics & Telecommunications Engineering
CERTIFICATE
This is to certify that M/S Saman Panchal
SAP ID 60002240043 of S.Y. [Link], EXTC has submitted a Mini Project for
the Python Programming Laboratory (DJS23EMD201) for the Academic Year
2025-2026
Course Instructor: - [Link] Sawant
INDEX
Sr. No. Title Page Number
1. Introduction 4
2. Proposed Methodology 5
3. Flow Chart and Algorithm 6
4. Code and Output 9
5. Conclusion 14
1. Introduction
This mini project implements a voice-controlled personal assistant written in
Python. The assistant listens for a wake word (configurable), recognizes spoken
commands using Google Speech Recognition (via the speech_recognition
library), and executes tasks such as opening websites/apps, playing music,
fetching news via a web API, and forwarding unrecognized or complex queries
to an AI service (OpenAI). It also provides text-to-speech (TTS) output using
pyttsx3 as the primary TTS engine and gTTS + pygame as a networked
fallback.
The main objectives are:
• Demonstrate real-time speech capture and recognition.
• Implement robust text-to-speech with offline and online fallbacks.
• Integrate simple web interactions (open URLs, search YouTube) and
external APIs (news, AI chat).
• Provide a modular codebase that is easy to extend and debug.
2. Proposed Methodology
The assistant is implemented as a single Python program composed of modular
functions for TTS, ASR (automatic speech recognition), command parsing, and
action execution.
Key components:
• Speech-to-Text: speech_recognition.Recognizer with recognize_google
for converting microphone audio to text.
• Wake-word loop: Continuous listening with short timeouts; the assistant
activates when its name appears in recognized text.
• Command processor: process_command() which maps recognized
phrases to actions (open websites, play songs, fetch news, call AI for
general responses).
• Text-to-Speech: pyttsx3 for offline TTS; if unavailable, gTTS creates an
MP3 and [Link] plays it.
• External APIs: News via [Link] (if key present); AI responses via
OpenAI API (if key present).
• Robustness features: Ambient noise calibration, exception handling
around audio and network calls, debug logging for TTS branches.
Development and testing strategy:
1. Start with core microphone capture and speech_recognition tests.
2. Add pyttsx3 TTS and test offline playback.
3. Implement command mapping and safe fallbacks (web search if song not
found).
4. Add optional features (news, AI) guarded by environment variables.
5. Add verbose debug logging and a speak_test() to validate TTS at startup.
3. Flow Chart and Algorithm
Here is a short algorithm you can use for your lab journal, based on the logic in
your Python script.
This algorithm describes the high-level flow of your voice assistant.
Algorithm: Voice Assistant Logic
1. Initialization
• Start: Program execution begins.
• Load Config: Read API keys (OpenAI, News) and the
ASSISTANT_NAME from the .env file.
• Init TTS: Initialize the Text-to-Speech engine.
o Attempt to load the offline engine (pyttsx3).
o Prepare the online fallback (gTTS with pygame) in case the offline
one fails.
• Init STT: Initialize the Speech Recognition (sr) library and open the
default microphone.
• Calibrate: Listen for 1 second to adjust the recognizer for ambient noise.
• Greet: Announce that the assistant is initialized and ready.
2. Main Execution Loop
• Start Loop: Begin an infinite while True loop to continuously listen.
• Listen for Wake Word:
o Listen for audio from the microphone.
o Transcribe the audio to text using Google Speech Recognition.
o If transcription fails (e.g., silence, network error), return to start of
Step 2.
• Check Activation:
o Check if the transcribed text contains the ASSISTANT_NAME
(e.g., "buddy").
o If NO: The wake word was not heard. Return to step 2
o If YES:
a. Speak an acknowledgment (e.g., "Yes Boss").
b. Listen for Command: Listen again for a new, full command
from the user.
c. Transcribe this new command audio to text.
d. If transcription fails, speak an error message ("Sorry, I didn't
catch that") and return to Step 2 .
e. Process Command: Send the transcribed command to the
Command Processing function (see Algorithm 3).
f. If the processing function returns an "exit" signal, break the main
loop.
• Shutdown: Once the loop is broken, speak a "Goodbye" message and
terminate the program.
3. Command Processing Function (process_command)
• Receive Text: Get the transcribed command string from the Main Loop.
• Check for Local Commands:
o if command is "open google", "open youtube", etc.:
▪ Speak "Opening [Site Name]" and use webbrowser to open
the URL.
o Elif command is "open spotify":
▪ Speak "Opening Spotify" and use [Link] to launch the
local application.
o Elif command starts with "play":
▪ Extract the song_name from the command.
▪ if song_name is in the local musicLibrary dictionary, open
its URL.
▪ Else, search for the song_name on YouTube.
o Elif command contains "news":
▪ Call the get_news() function to fetch and speak the top 5
headlines from the NewsAPI.
o Elif command is "exit" or "quit":
▪ Speak "Goodbye" and return an "exit" signal.
• Handle General Queries (Default):
o Else (if no local command matches):
▪ Send the entire command text to the OpenAI API
(ai_process function).
▪ Receive the text-based response from the AI.
▪ Speak the AI's response.
4. Code and Output
5. Conclusion
This mini project demonstrates an integrative voice assistant that combines
speech recognition, TTS (offline + online fallback), web interactions, and
optional AI integration. The main limitation encountered is environment-
dependent audio playback — common in headless systems, WSL, or when
drivers are missing. The code includes diagnostic prints and a speak_test()
helper to help identify whether pyttsx3 or the gTTS fallback is being used.