Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions alexa-assistant/AlexaProject.py
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions alexa-assistant/README.md
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions alexa-assistant/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
speechrecognition
pyttsx3
pyaudio
requests
openai