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

Jarvis Final Modules

The document outlines the final modules for a system named JARVIS, including a core module, memory module, and security module. The memory module utilizes SQLite for storing learned responses and includes functions for backup and restoration. The security module implements voice recognition and text-to-speech capabilities to manage security protocols and handle potential flaws.
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)
9 views3 pages

Jarvis Final Modules

The document outlines the final modules for a system named JARVIS, including a core module, memory module, and security module. The memory module utilizes SQLite for storing learned responses and includes functions for backup and restoration. The security module implements voice recognition and text-to-speech capabilities to manage security protocols and handle potential flaws.
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

# ===========================

# JARVIS FINAL MODULES (Khush)


# ===========================

# -------- CORE MODULE --------


# [Placeholder] Add your actual Core Module code here.

# -------- MEMORY MODULE --------


import sqlite3
import shutil
import os

DB_PATH = "jarvis_memory.db"
BACKUP_DIR = "backups"
BACKUP_FILE = f"{BACKUP_DIR}/jarvis_memory_backup.db"

# Initialize DB connection and cursor


conn = sqlite3.connect(DB_PATH, check_same_thread=False)
cursor = conn.cursor()

def init_db():
cursor.execute("""
CREATE TABLE IF NOT EXISTS learning (
id INTEGER PRIMARY KEY AUTOINCREMENT,
query TEXT UNIQUE,
correct_response TEXT
)
""")
conn.commit()

def save_learning(query, response):


cursor.execute("INSERT OR REPLACE INTO learning (query, correct_response)
VALUES (?, ?)", (query, response))
conn.commit()

def get_learned_response(query):
cursor.execute("SELECT correct_response FROM learning WHERE query = ?",
(query,))
result = cursor.fetchone()
return result[0] if result else None

def backup_memory():
os.makedirs(BACKUP_DIR, exist_ok=True)
try:
shutil.copy(DB_PATH, BACKUP_FILE)
print("Memory backup completed.")
except Exception as e:
print(f"Backup failed: {e}")

def restore_backup():
if os.path.exists(BACKUP_FILE):
shutil.copy(BACKUP_FILE, DB_PATH)
print("Memory successfully restored from backup.")
else:
print("Backup file not found. Cannot restore.")

# Initialize DB on import
init_db()
# -------- SECURITY MODULE --------
import os
import time
import queue
import json
import sounddevice as sd
import pyttsx3
import vosk

# Configuration
BACKUP_DIR = "backups"
TOKEN = "stark protocol 121110"
EXIT_TOKEN = "exit stark protocol 121110"

# Setup TTS and speech recognition


engine = pyttsx3.init()
engine.setProperty('rate', 180)
model = vosk.Model(lang="en-us")
q = queue.Queue()

def speak(text):
print(f"Jarvis: {text}")
engine.say(text)
engine.runAndWait()

def listen_voice(timeout=45):
start_time = time.time()
def callback(indata, frames, time_info, status):
q.put(bytes(indata))

with sd.RawInputStream(samplerate=16000, blocksize=8000, dtype='int16',


channels=1, callback=callback):
rec = vosk.KaldiRecognizer(model, 16000)
while time.time() - start_time < timeout:
data = q.get()
if rec.AcceptWaveform(data):
result = json.loads(rec.Result())
command = result.get("text", "").lower()
if command:
print(f"You: {command}")
return command
return ""

def backup_memory(memory_backup_func):
speak("Starting memory backup...")
memory_backup_func()
speak("Memory backup completed, Sir.")

def initiate_quarantine():
speak("No response received. System entering quarantine mode.")
open("quarantine.lock", "w").close()
while True:
speak("Awaiting exit token.")
response = listen_voice()
if EXIT_TOKEN in response:
speak("Exiting quarantine. Welcome back, Sir.")
os.remove("quarantine.lock")
break
def handle_flaw():
speak("Sir, a flaw has been detected. Shall I attempt to neutralize it?")
response = listen_voice()
if "yes" in response:
speak("Please confirm with security token.")
token = listen_voice()
if TOKEN in token:
speak("Flaw neutralized, Sir.")
else:
speak("Invalid token. Aborting neutralization.")
else:
speak("Acknowledged. Flaw report secured.")

def initiate_security_protocols(memory_backup_func):
speak("Running security protocols.")
backup_memory(memory_backup_func)
speak("A potential flaw has been found. Shall I initiate quarantine mode?")
response = listen_voice()
if "yes" in response:
initiate_quarantine()
elif not response:
initiate_quarantine()
else:
handle_flaw()

You might also like