It takes microphone input from the user and returns string output
()
| 34 | speak("Good night") |
| 35 | speak("Hello I am your personal desktop assistant. Please tell me how may i help you ") |
| 36 | def takeCommand(): |
| 37 | '''It takes microphone input from the user and returns string output''' |
| 38 | r=sr.Recognizer() |
| 39 | with sr.Microphone() as source: |
| 40 | speak("Go Ahead, I am listening to you......") |
| 41 | print("Go Ahead, I am listening to you......") |
| 42 | r.pause_threshold = 1 |
| 43 | audio=r.listen(source) |
| 44 | |
| 45 | try: |
| 46 | print("Recognizing") |
| 47 | |
| 48 | query=r.recognize_google(audio, language='hi-in') |
| 49 | print(f"User said:{query}\n") |
| 50 | except Exception as e: |
| 51 | #print(e) |
| 52 | speak("sorry i can't able to hear you Say that again please....") |
| 53 | return "None" |
| 54 | return query |
| 55 | |
| 56 | |
| 57 |