| 34 | |
| 35 | |
| 36 | def takeCommand(): |
| 37 | # Function to listen to user's voice input and return the recognized text |
| 38 | r = sr.Recognizer() |
| 39 | with sr.Microphone() as source: |
| 40 | print("Listening...") |
| 41 | r.pause_threshold = 1 |
| 42 | audio = r.listen(source) |
| 43 | |
| 44 | try: |
| 45 | print("Recognizing...") |
| 46 | query = r.recognize_google(audio, language="en-in") |
| 47 | print(f"User said: {query}\n") |
| 48 | |
| 49 | except Exception as e: |
| 50 | # If speech recognition fails, prompt the user to repeat the command |
| 51 | print("Could you please repeat it, sir...") |
| 52 | return "None" |
| 53 | return query |
| 54 | |
| 55 | |
| 56 | def sendEmail(to, content): |