Code
Code
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
# 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
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 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