Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Kamesh Raj
Published © LGPL

Alpha

Introducing Alpha, your all-in-one voice-activated personal assistant. it is a Python-based program equipped with speech recognition

AdvancedFull instructions provided5 hours134
Alpha

Things used in this project

Story

Read more

Schematics

Alpha - Source Code

Code

Alpha - Source Code

Python
import re
import pyttsx3
import pywhatkit
import speech_recognition as sr
import requests
import webbrowser
import smtplib
import psutil
import pyautogui
import os
import speedtest
import pyjokes

engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)


def speak(text):
    engine.say(text)
    engine.runAndWait()


def take_command():
    recognizer = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        recognizer.adjust_for_ambient_noise(source)
        audio = recognizer.listen(source, timeout=5)
        command = ""
        try:
            print("Recognizing...")
            command = recognizer.recognize_google(audio).lower()
            print("You said: " + command)
        except sr.UnknownValueError:
            print("Could not understand audio.")
        except sr.RequestError as e:
            print(f"Could not request results from Google Speech Recognition service; {e}")
        return command


def parse_command(command):
    # Using regular expressions to extract relevant information
    match = re.search(r'(open|search|play)\s+(\w+)', command)
    if match:
        action = match.group(1)
        query = match.group(2)
        return action, query
    else:
        return None, None


def perform_action(action, query):
    if action == 'open':
        if query.lower() == 'youtube':
            webbrowser.open('https://www.youtube.com')
        elif query.lower() == 'google':
            webbrowser.open('https://www.google.com')
        # Add more 'open' commands for other applications or websites
    elif action == 'search':
        webbrowser.open(f'https://www.google.com/search?q={query}')
    elif action == 'play':
        pywhatkit.playonyt(query)


def get_ip_address():
    ip_address = requests.get('https://api.ipify.org').text
    print(f"Your IP address is: {ip_address}")
    speak(f"Your IP address is {ip_address}.")


def get_speed():
    tester = speedtest.SpeedTest()
    download_speed = tester.download()
    upload_speed = tester.upload()
    print(f"Download speed: {download_speed / 8 / 1000} Mbps")
    print(f"Upload speed: {upload_speed / 8 / 1000} Mbps")
    speak(f"Your download speed is {download_speed / 8 / 1000} megabits per second and your upload speed is {upload_speed / 8 / 1000} megabits per second.")


def get_system_stats():
    cpu_usage = psutil.cpu_percent()
    memory_usage = psutil.virtual_memory().percent
    print(f"CPU usage: {cpu_usage}%")
    

def tell_joke():
    joke = pyjokes.get_joke()
    speak(joke)




if __name__ == "__main__":
    speak("Hello! I am Alpha")
    while True:
        command = take_command()
        action, query = parse_command(command)

        if action:
            perform_action(action, query)
        elif "ip address" in command:
            get_ip_address()
        elif "speed" in command:
            get_speed()
        elif "system stats" in command:
            get_system_stats()
        elif "joke" in command:
            tell_joke()
        elif any(word in command for word in ["exit", "stop", "quit"]):
            speak("Good Bye")
            break
        else:
            print("Recognized command:", command)
            speak("I'm sorry, I don't understand that command. Please try again.")

Credits

Kamesh Raj
4 projects • 1 follower
A driven and adaptable engineering student with business acumen, seeking to leverage my skills and passion for computer science.
Contact

Comments

Please log in or sign up to comment.