| 123 | |
| 124 | # obtain audio from the microphone |
| 125 | def takecommand(): |
| 126 | # it takes user's command and returns string output |
| 127 | wishme() |
| 128 | r = sr.Recognizer() |
| 129 | with sr.Microphone() as source: |
| 130 | print("Listening...") |
| 131 | r.pause_threshold = 1 |
| 132 | r.dynamic_energy_threshold = 500 |
| 133 | audio = r.listen(source) |
| 134 | try: |
| 135 | print("Recognizing...") |
| 136 | query = r.recognize_google(audio, language="en-in") |
| 137 | print(f"User said {query}\n") |
| 138 | except Exception: |
| 139 | print("Say that again please...") |
| 140 | return "None" |
| 141 | return query |
| 142 | |
| 143 | |
| 144 | # for audio output instead of print |