Jarvis / jarvis.py
Banu007's picture
Upload jarvis.py
6c46cd0 verified
import os
import subprocess
import requests
from datetime import datetime
# --- CONFIG ---
COLAB_URL = "https://56a0-35-197-74-67.ngrok-free.app/chat"
MODEL_PATH = "/data/data/com.termux/files/home/jarvis/voice/en_US-amy-medium.onnx"
PIPER_BIN = "/data/data/com.termux/files/home/jarvis/voice/bin/piper"
OUT_FILE = "/data/data/com.termux/files/home/jarvis/voice/out.wav"
def speak(text):
print(f"JARVIS: {text}")
os.system(f"proot-distro login debian -- {PIPER_BIN} --model {MODEL_PATH} --output_file {OUT_FILE} << 'EOF'\n{text}\nEOF")
os.system(f"termux-media-player play {OUT_FILE}")
def open_app(app_name):
"""Automatically searches and opens any app on your Realme 7."""
target = app_name.lower().strip()
# 1. First, check our "Fast List" for common apps
fast_list = {
"youtube": "https://www.youtube.com",
"whatsapp": "whatsapp://send",
"chrome": "googlechrome://",
"facebook": "fb://",
"instagram": "instagram://",
"calculator": "calc://"
}
speak(f"Searching for {target}...")
if target in fast_list:
os.system(f"termux-open-url {fast_list[target]}")
return
# 2. If it's a game (like Free Fire) or something else, search the system
# This command asks Android to find the best app for the name
try:
# This will open the Play Store or the App directly if installed
os.system(f"termux-open-url intent:#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;component={target};end")
# Fallback: Just search for it if the intent fails
os.system(f"termux-open-url https://www.google.com/search?q={target}+android+app+open")
except:
speak(f"I couldn't find a path to {target} on this device.")
def listen():
print("\n[Listening...]")
try:
return subprocess.check_output("termux-speech-to-text", shell=True).decode("utf-8").lower().strip()
except:
return input("Type command: ").lower().strip()
# --- MAIN LOOP ---
os.system("clear")
speak("Universal app access enabled. Which app should I open, Tamil?")
while True:
query = listen()
if not query: continue
print(f"Tamil: {query}")
if "open" in query:
app_to_open = query.replace("open", "").strip()
open_app(app_to_open)
elif "exit" in query or "stop" in query:
speak("Goodbye, Tamil.")
break
else:
try:
r = requests.post(COLAB_URL, json={"message": query}, timeout=15)
speak(r.json().get("reply", "Brain is thinking..."))
except:
speak("Brain connection lost.")