From 86ba9ff07672fa2067dbd7aeb639e176256f1742 Mon Sep 17 00:00:00 2001 From: yeshu Date: Sat, 22 Nov 2025 19:05:57 +0530 Subject: [PATCH] Add Alexa Assistant project --- alexa-assistant/AlexaProject.py | 61 ++++++++++++++++++++++++++++++++ alexa-assistant/README.md | 16 +++++++++ alexa-assistant/requirements.txt | 5 +++ 3 files changed, 82 insertions(+) create mode 100644 alexa-assistant/AlexaProject.py create mode 100644 alexa-assistant/README.md create mode 100644 alexa-assistant/requirements.txt diff --git a/alexa-assistant/AlexaProject.py b/alexa-assistant/AlexaProject.py new file mode 100644 index 000000000..602d1ed53 --- /dev/null +++ b/alexa-assistant/AlexaProject.py @@ -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 + diff --git a/alexa-assistant/README.md b/alexa-assistant/README.md new file mode 100644 index 000000000..304bb1eab --- /dev/null +++ b/alexa-assistant/README.md @@ -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 + diff --git a/alexa-assistant/requirements.txt b/alexa-assistant/requirements.txt new file mode 100644 index 000000000..5a486281f --- /dev/null +++ b/alexa-assistant/requirements.txt @@ -0,0 +1,5 @@ +speechrecognition +pyttsx3 +pyaudio +requests +openai