-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_python.py
More file actions
167 lines (146 loc) · 5.52 KB
/
run_python.py
File metadata and controls
167 lines (146 loc) · 5.52 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python3
"""Python-only launcher — no Swift/Xcode required.
Uses BlackHole for audio capture (no Screen Recording permission needed).
Run entirely from Cursor: develop, test, and use without opening Xcode.
Prerequisites:
1. brew install blackhole-2ch ffmpeg
2. Create Multi-Output Device in Audio MIDI Setup: Speakers + BlackHole 2ch
3. Set system output to that Multi-Output Device (so audio routes to BlackHole)
4. config.yaml: audio_capture_method: blackhole
Usage:
python run_python.py
# Or: ./run_python.py
"""
import sys
import subprocess
import threading
import time
import webbrowser
from pathlib import Path
# Add project root to path
sys.path.insert(0, str(Path(__file__).parent))
def check_config():
"""Ensure BlackHole is configured."""
try:
from src.config import Config
config = Config()
method = config.get('audio_capture_method', 'auto').lower()
if method not in ('blackhole', 'auto'):
print("⚠️ Set audio_capture_method to 'blackhole' in config.yaml for Python-only mode.")
print(" (SystemAudioDump requires Swift app for Screen Recording permission)")
response = input("Continue anyway? [y/N]: ").strip().lower()
if response != 'y':
sys.exit(1)
except Exception as e:
print(f"Config check failed: {e}")
def main():
# Optional: force blackhole for Python-only
if "--force-blackhole" in sys.argv:
try:
from src.config import Config
Config().set("audio_capture_method", "blackhole")
print("✓ Set audio_capture_method to blackhole")
except Exception as e:
print(f"Could not update config: {e}")
print("=" * 60)
print("Local Meeting Assistant — Python-only mode")
print("=" * 60)
print()
print("No Xcode/Swift required. Uses BlackHole for audio (no Screen Recording permission).")
print()
check_config()
print()
# Start backend
backend_script = Path(__file__).parent / "backend_server.py"
if not backend_script.exists():
print(f"❌ Backend not found: {backend_script}")
sys.exit(1)
print("Starting backend server...")
proc = subprocess.Popen(
[sys.executable, str(backend_script), "--port", "8000"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=Path(__file__).parent,
text=True,
)
# Wait for backend to be ready
import urllib.request
for i in range(30):
try:
urllib.request.urlopen("http://127.0.0.1:8000/api/health", timeout=1)
print("✓ Backend ready at http://127.0.0.1:8000")
break
except Exception:
time.sleep(0.5)
else:
print("❌ Backend failed to start. Check logs above.")
proc.terminate()
sys.exit(1)
print()
print("Recording controls (via API):")
print(" Start: curl -X POST http://127.0.0.1:8000/api/recording/start -H 'Content-Type: application/json' -d '{}'")
print(" Stop: curl -X POST http://127.0.0.1:8000/api/recording/stop")
print()
print("Or open the simple UI...")
print()
# Simple GUI (tkinter is built-in)
try:
import tkinter as tk
from tkinter import messagebox
import urllib.request
import json
def api_post(path: str, data: dict = None) -> bool:
try:
req = urllib.request.Request(
f"http://127.0.0.1:8000{path}",
data=json.dumps(data or {}).encode() if data else None,
headers={"Content-Type": "application/json"} if data else {},
method="POST",
)
urllib.request.urlopen(req, timeout=10)
return True
except Exception as e:
messagebox.showerror("API Error", str(e))
return False
root = tk.Tk()
root.title("Local Meeting Assistant")
root.geometry("320x120")
root.resizable(False, False)
status = tk.Label(root, text="Ready", font=("", 11))
status.pack(pady=(10, 5))
def on_start():
if api_post("/api/recording/start", {"session_title": "Meeting"}):
status.config(text="● Recording...", fg="red")
btn_start.config(state="disabled")
btn_stop.config(state="normal")
def on_stop():
if api_post("/api/recording/stop"):
status.config(text="Processing...", fg="orange")
btn_start.config(state="normal")
btn_stop.config(state="disabled")
root.after(2000, lambda: status.config(text="Ready", fg="black"))
btn_start = tk.Button(root, text="Start Recording", command=on_start, width=20)
btn_start.pack(pady=5)
btn_stop = tk.Button(root, text="Stop Recording", command=on_stop, width=20, state="disabled")
btn_stop.pack(pady=5)
def on_closing():
proc.terminate()
proc.wait(timeout=3)
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()
except ImportError:
# Fallback: TUI
print("(tkinter not available, use curl to control recording)")
try:
while True:
input("Press Enter to quit...")
break
except KeyboardInterrupt:
pass
finally:
proc.terminate()
proc.wait(timeout=5)
print("Backend stopped.")
if __name__ == "__main__":
main()