()
| 97 | |
| 98 | |
| 99 | def voice_loop(): |
| 100 | say("Ready.") |
| 101 | print("Listening stays on. Speak when you want something, or say 'type mode' to write.") |
| 102 | check_lm_studio() |
| 103 | apps = build_application_index() |
| 104 | say(f"Safe app index ready: {len(apps)} apps found.") |
| 105 | |
| 106 | recognizer = sr.Recognizer() |
| 107 | recognizer.pause_threshold = 2 |
| 108 | recognizer.non_speaking_duration = 1 |
| 109 | |
| 110 | try: |
| 111 | with sr.Microphone() as source: |
| 112 | print("Calibrating microphone...") |
| 113 | recognizer.adjust_for_ambient_noise(source, duration=1) |
| 114 | while True: |
| 115 | user_input = listen_once(recognizer, source, choose_best_candidate) |
| 116 | if not user_input: |
| 117 | print("No clear speech detected. Continuing to listen...") |
| 118 | continue |
| 119 | if should_exit(user_input): |
| 120 | say("Goodbye.") |
| 121 | break |
| 122 | if wants_type_mode(user_input): |
| 123 | typed = input("Type to Jarvis: ").strip() |
| 124 | if typed: |
| 125 | print(f"You typed: {typed}") |
| 126 | if should_exit(typed): |
| 127 | say("Goodbye.") |
| 128 | break |
| 129 | handle_and_say(typed) |
| 130 | print("Listening again...") |
| 131 | continue |
| 132 | if normalize_text(user_input) in {"refresh apps", "uygulamalari yenile", "uygulamaları yenile"}: |
| 133 | apps = build_application_index() |
| 134 | say(f"Safe app index refreshed: {len(apps)} apps found.") |
| 135 | continue |
| 136 | handle_and_say(user_input) |
| 137 | except KeyboardInterrupt: |
| 138 | print() |
| 139 | say("Goodbye.") |
| 140 | except Exception as exc: |
| 141 | say(f"Microphone error: {exc}") |
| 142 | print("Falling back to type mode.") |
| 143 | typed_loop() |
| 144 | |
| 145 | |
| 146 | def typed_loop(): |
no test coverage detected