0% found this document useful (0 votes)
11 views3 pages

Code

Uploaded by

EminentFate100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Code

Uploaded by

EminentFate100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import pyttsx3

import speech_recognition as sr
import psutil
import os
import shutil
import logging
import random
import speedtest
import spacy
import requests
from textblob import TextBlob

# Initialize the English language model for NLP


nlp = spacy.load("en_core_web_sm")

# Dictionary of response templates for Customizable Responses


responses = {
"greetings": ["Hello!", "Hi there!", "Hey!"],
"farewell": ["Goodbye!", "See you later!", "Take care!"]
}

# Define conversation states for Interactive Dialogues


class ConversationManager:
def __init__(self):
self.state = "start"

def process_input(self, user_input):


if self.state == "start":
if "hello" in user_input.lower():
self.state = "greeted"
return "Hi there! How can I assist you?"
else:
return "Hello! How can I assist you?"

elif self.state == "greeted":


if "help" in user_input.lower():
self.state = "asked_for_help"
return "Sure, I'm here to help! What do you need assistance with?"
else:
return "How can I assist you today?"

elif self.state == "asked_for_help":


# Handle user requests for assistance
return "Sure, let me know how I can assist you."

# Function to parse user input for Enhanced NLU


def parse_input(input_text):
doc = nlp(input_text)
# Extract entities, keywords, or intents from the input text
entities = [ent.text for ent in doc.ents]
keywords = [token.text for token in doc if not token.is_stop and
token.is_alpha]
return entities, keywords

# Function to generate a response based on a template key for Customizable


Responses
def generate_response(template_key):
if template_key in responses:
return random.choice(responses[template_key])
else:
return "I'm sorry, I don't understand that."

# Function to retrieve data from an external API for Integration with External APIs
def get_api_data(api_url):
try:
response = requests.get(api_url)
if response.status_code == 200:
return response.json()
else:
return None
except requests.exceptions.RequestException as e:
print("Error:", e)
return None

# Function to analyze sentiment of text for Emotion Recognition


def analyze_sentiment(text):
blob = TextBlob(text)
sentiment_score = blob.sentiment.polarity
if sentiment_score > 0.5:
return "positive"
elif sentiment_score < -0.5:
return "negative"
else:
return "neutral"

class VoiceAssistant:
def __init__(self):
logging.basicConfig(level=logging.DEBUG) # Set logging level to DEBUG
self.engine = pyttsx3.init()
self.recognizer = sr.Recognizer()
self.voices = self.engine.getProperty('voices')
self.voice_index = 0
self.rude_threshold = 0.5 # Adjust this threshold as needed
logging.info("Voice Assistant initialized.")
self.conversation_manager = ConversationManager()

def listen(self):
try:
with sr.Microphone() as source:
logging.debug("Listening for command...")
audio = self.recognizer.listen(source)
logging.debug("Audio captured.")
command = self.recognizer.recognize_google(audio).lower()
logging.debug(f"Recognized command: {command}")
return command
except sr.UnknownValueError:
logging.debug("Speech recognition could not understand audio.")
return None
except sr.RequestError as e:
logging.error(f"Could not request results from Google Speech
Recognition service: {e}")
return None

def speak(self, text):


logging.debug(f"Speaking: {text}")
self.engine.say(text)
self.engine.runAndWait()
logging.debug("Speech completed.")
def change_voice(self):
self.voice_index = (self.voice_index + 1) % len(self.voices)
self.engine.setProperty('voice', self.voices[self.voice_index].id)
logging.info(f"Changed voice to: {self.voices[self.voice_index].name}")

def insult(self):
insults = ["You're a waste of oxygen.", "I'd tell you to go fuck yourself,
but I'm sure you'd be disappointed.",
"You're as useless as a knitted condom.", "I'd slap you, but
shit splatters.",
"Your birth certificate is an apology letter from the condom
factory.", "You're not pretty enough to be this stupid.",
"If you had a brain, it would be lonely.", "You're about as
useful as a screen door on a submarine.",
"I'd call you a cunt, but you lack the warmth and depth.",
"You're proof that evolution can go in reverse.",
"You're not pretty enough to be this stupid.", "The only way
you'll ever get laid is if you crawl up a chicken's ass and wait.",
"Your family tree is a cactus, because everybody on it is a
prick.", "I refuse to engage in a battle of wits with an unarmed person.",
"You're so ugly, when your mom dropped you off at school, she
got a fine for littering.",
"You're not just wrong, you're stupid.", "I'd agree with you,
but then we'd both be wrong.",
"You're the reason the gene pool needs a lifeguard.", "You're
like Mondays, nobody likes you.",
"I'd call you dumb as a rock, but at least a rock has a use.",
"If laughter is the best medicine, your face must be curing the world.",
"You're so fat, you have to use a selfie stick to get your belt
buckle in the shot.", "Is your ass jealous of the amount of shit that just came out
of your mouth?",
"The only way you'll ever get laid is if you crawl up a
chicken's ass and wait.", "You're like a hemorrhoid, a pain in the ass who won't go
away.",
"You're the human version of period cramps.", "You're not pretty
enough to be this stupid.",
"You're not just a douchebag, you're the entire douche.", "If
you're going to be a smartass, first you have to be smart. Otherwise, you're just
an ass."]
return random.choice(insults)

def insult_response(self):
if random.random() > self.rude_threshold:
self.speak(self.insult())
else:
self.speak("Sure, I can help you with that.")

def get_disk_space(self):
total, used, free = shutil.disk_usage("/")
self.speak(f"Total disk space: {total // (2**30)} gigabytes.")
self.speak(f"Used disk space: {used // (2**30)} gigabytes.")
self.speak(f"Free disk space: {free // (2**30)} gigabytes.")

def get_cpu_usage(self):
self.speak(f"CPU usage: {ps

You might also like