wip update
changing pc again /do not commit
evrardt committed
Aug 7, 2024 at 23:08 UTC
c6b23084137aeff9924411348a6bd911bd2dd3ba
1 file changed
+15
-3
main.py
+15
-3
@@ -7,6 +7,7 @@ from python.helpers.files import read_file
7
from python.helpers import files
8
import python.helpers.timed_input as timed_input
9
from tts import TTS
10
+from pynput import keyboard
11
12
input_lock = threading.Lock()
13
os.chdir(files.get_abs_path("./work_dir")) #change CWD to work_dir
@@ -87,22 +88,29 @@ def chat(agent:Agent):
88
if not timeout: # if agent wants to wait for user input forever
89
PrintStyle(background_color="#6C3483", font_color="white", bold=True, padding=True).print(f"User message ('e' to leave):")
90
import readline # this fixes arrow keys in terminal
91
+ listener = keyboard.Listener(on_press=on_press)
92
+ listener.start()
93
user_input = input("> ")
94
+ listener.stop()
95
PrintStyle(font_color="white", padding=False, log_only=True).print(f"> {user_input}")
96
97
else: # otherwise wait for user input with a timeout
98
PrintStyle(background_color="#6C3483", font_color="white", bold=True, padding=True).print(f"User message ({timeout}s timeout, 'w' to wait, 'e' to leave):")
99
import readline # this fixes arrow keys in terminal
96
- # user_input = timed_input("> ", timeout=timeout)
100
+ listener = keyboard.Listener(on_press=on_press)
101
+ listener.start()
102
user_input = timeout_input("> ", timeout=timeout)
98
-
103
+ listener.stop()
104
if not user_input:
105
user_input = read_file("prompts/fw.msg_timeout.md")
106
PrintStyle(font_color="white", padding=False).stream(f"{user_input}")
107
else:
108
user_input = user_input.strip()
109
if user_input.lower()=="w": # the user needs more time
105
- user_input = input("> ").strip()
110
+ listener = keyboard.Listener(on_press=on_press)
111
+ listener.start()
112
+ user_input = input("> ")
113
+ listener.stop()
114
PrintStyle(font_color="white", padding=False, log_only=True).print(f"> {user_input}")
115
116
@@ -132,6 +140,10 @@ def intervention():
140
if user_input: Agent.streaming_agent.intervention_message = user_input # set intervention message if non-empty
141
Agent.paused = False # continue agent streaming
142
143
+def on_press(key):
144
+ if key == keyboard.Key.alt_r:
145
+ # Lancer le speech to text
146
+ stt.record()
147
148
# Capture keyboard input to trigger user intervention
149
def capture_keys():