Skip to content

Commit cd08721

Browse files
committed
Add missing voice_mode code that for some reason is not being tracked / merged
1 parent d687e14 commit cd08721

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

operate/main.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def supports_ansi():
194194
ANSI_BRIGHT_MAGENTA = ""
195195

196196

197-
def main(model, accurate_mode):
197+
def main(model, accurate_mode, voice_mode=False):
198198
"""
199199
Main function for the Self-Operating Computer
200200
"""
@@ -222,18 +222,25 @@ def main(model, accurate_mode):
222222
).run()
223223

224224
print("SYSTEM", platform.system())
225-
225+
# Clear the console
226226
if platform.system() == "Windows":
227227
os.system("cls")
228228
else:
229229
print("\033c", end="")
230230

231-
print(f"{ANSI_GREEN}[Self-Operating Computer]\n{ANSI_RESET}{USER_QUESTION}")
232-
print(f"{ANSI_YELLOW}[User]{ANSI_RESET}")
233-
234-
objective = prompt(
235-
style=style,
236-
)
231+
if voice_mode:
232+
print(
233+
f"{ANSI_GREEN}[Self-Operating Computer]{ANSI_RESET} Listening for your command... (speak now)"
234+
)
235+
try:
236+
objective = mic.listen()
237+
except Exception as e:
238+
print(f"{ANSI_RED}Error in capturing voice input: {e}{ANSI_RESET}")
239+
return # Exit if voice input fails
240+
else:
241+
print(f"{ANSI_GREEN}[Self-Operating Computer]\n{ANSI_RESET}{USER_QUESTION}")
242+
print(f"{ANSI_YELLOW}[User]{ANSI_RESET}")
243+
objective = prompt(style=style)
237244

238245
assistant_message = {"role": "assistant", "content": USER_QUESTION}
239246
user_message = {
@@ -815,6 +822,13 @@ def main_entry():
815822
default="gpt-4-vision-preview",
816823
)
817824

825+
# Add a voice flag
826+
parser.add_argument(
827+
"--voice",
828+
help="Use voice input mode",
829+
action="store_true",
830+
)
831+
818832
parser.add_argument(
819833
"-accurate",
820834
help="Activate Reflective Mouse Click Mode",
@@ -824,7 +838,7 @@ def main_entry():
824838

825839
try:
826840
args = parser.parse_args()
827-
main(args.model, accurate_mode=args.accurate)
841+
main(args.model, accurate_mode=args.accurate, voice_mode=args.voice)
828842
except KeyboardInterrupt:
829843
print(f"\n{ANSI_BRIGHT_MAGENTA}Exiting...")
830844

0 commit comments

Comments
 (0)