-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (42 loc) · 1.76 KB
/
main.py
File metadata and controls
49 lines (42 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import time
import threading
from kivy.app import App
from kivy.uix.label import Label
from jnius import autoclass
from llama_cpp import Llama
from vosk import Model, KaldiRecognizer
import pyttsx3
# Android System Classes
PythonActivity = autoclass('org.kivy.android.PythonActivity')
Context = autoclass('android.content.Context')
TelephonyManager = autoclass('android.telephony.TelephonyManager')
AudioManager = autoclass('android.media.AudioManager')
class AICallBot(App):
def build(self):
self.label = Label(text="Bot Active: Waiting for Call")
# Load Local AI
self.llm = Llama(model_path="models/qwen.gguf", n_ctx=512)
self.stt_model = Model("models/vosk-model")
self.engine = pyttsx3.init()
# Start Call Monitoring Thread
threading.Thread(target=self.monitor_calls, daemon=True).start()
return self.label
def monitor_calls(self):
tm = PythonActivity.mActivity.getSystemService(Context.TELEPHONY_SERVICE)
while True:
state = tm.getCallState()
if state == TelephonyManager.CALL_STATE_RINGING:
print("Detected Ringing... Waiting 20s")
time.sleep(20)
# Check if still ringing
if tm.getCallState() == TelephonyManager.CALL_STATE_RINGING:
self.start_ai_session()
time.sleep(1)
def start_ai_session(self):
# Force Speakerphone so the AI can 'hear' the caller
audio = PythonActivity.mActivity.getSystemService(Context.AUDIO_SERVICE)
audio.setMode(AudioManager.MODE_IN_CALL)
audio.setSpeakerphoneOn(True)
# Voice Loop
self.engine.say("Hello, I am a local AI assistant answering for my owner. How can I help?")
self.engine.runAndWait()