| import speech_recognition as sr |
| import pyttsx3 |
| from ai_brain import get_ai_response |
|
|
| |
| engine = pyttsx3.init() |
| voices = engine.getProperty('voices') |
| |
| engine.setProperty('voice', voices[0].id) |
| engine.setProperty('rate', 170) |
|
|
| def speak(text): |
| """Text ko aawaz mein badalne ka function""" |
| print(f"Jarvis: {text}") |
| engine.say(text) |
| engine.runAndWait() |
|
|
| |
| recognizer = sr.Recognizer() |
|
|
| def listen(): |
| """Mic se aawaz sunkar text mein badalne ka function""" |
| with sr.Microphone() as source: |
| print("\nListening... (Aap bol sakte hain)") |
| |
| recognizer.adjust_for_ambient_noise(source, duration=0.5) |
| try: |
| audio = recognizer.listen(source, timeout=5, phrase_time_limit=10) |
| print("Processing...") |
| |
| command = recognizer.recognize_google(audio, language="en-IN") |
| print(f"You said: {command}") |
| return command |
| except sr.WaitTimeoutError: |
| pass |
| except sr.UnknownValueError: |
| print("Main samajh nahi paya, kripya fir se bolein.") |
| except sr.RequestError: |
| print("Speech service down hai.") |
| return "" |
|
|
| |
| def start_jarvis(): |
| speak("System is online. I am ready.") |
| |
| while True: |
| user_command = listen().lower() |
| |
| if "stop" in user_command or "exit" in user_command: |
| speak("Shutting down systems. Goodbye!") |
| break |
| |
| if user_command: |
| |
| response = get_ai_response(user_command) |
| |
| speak(response) |
|
|
| if __name__ == "__main__": |
| start_jarvis() |
| |