Add Alexa Assistant project

This commit is contained in:
yeshu 2025-11-22 19:05:57 +05:30
parent 1a851d83f7
commit 86ba9ff076
3 changed files with 82 additions and 0 deletions

View file

@ -0,0 +1,61 @@
*(If PyAudio gives error, users can install system version.)*
---
# ✅ 4. alexa.py (Core Code)
Paste this:
```python
import speech_recognition as sr
import pyttsx3
import datetime
import webbrowser
engine = pyttsx3.init()
def speak(text):
engine.say(text)
engine.runAndWait()
def listen():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
command = r.recognize_google(audio, language="en-in")
print("User said:", command)
except:
return ""
return command.lower()
speak("Hello, I am Alexa. How can I help you?")
while True:
cmd = listen()
if "time" in cmd:
time = datetime.datetime.now().strftime("%H:%M")
speak(f"The time is {time}")
elif "date" in cmd:
date = datetime.datetime.now().strftime("%d %B %Y")
speak(f"Today's date is {date}")
elif "search" in cmd:
query = cmd.replace("search", "")
webbrowser.open(f"https://www.google.com/search?q={query}")
speak("Searching Google")
elif "open youtube" in cmd:
speak("Opening YouTube")
webbrowser.open("https://youtube.com")
elif "exit" in cmd or "stop" in cmd:
speak("Goodbye")
break

16
alexa-assistant/README.md Normal file
View file

@ -0,0 +1,16 @@
# Build Your Own Alexa Assistant
This project shows how to build a basic Alexa-like voice assistant using Python. It listens to voice commands, answers questions, performs searches, tells the time, and can be extended easily.
## Features
- Voice recognition (SpeechRecognition)
- Text-to-Speech (pyttsx3)
- Online search functionality
- Time and date responses
- Custom command support
- Extendable skills system
## Installation
```bash
pip install -r requirements.txt

View file

@ -0,0 +1,5 @@
speechrecognition
pyttsx3
pyaudio
requests
openai