Skip to content

Instantly share code, notes, and snippets.

@KaushikShresth07
Created May 25, 2021 05:09
Show Gist options
  • Select an option

  • Save KaushikShresth07/aa832b43c3c0d7087b604cf24f1990e1 to your computer and use it in GitHub Desktop.

Select an option

Save KaushikShresth07/aa832b43c3c0d7087b604cf24f1990e1 to your computer and use it in GitHub Desktop.
import pyttsx3
import speech_recognition as sr
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[7].id)
engine.setProperty('rate',170)
def Speak(Audio):
print(" ")
print(f": {Audio}")
engine.say(Audio)
print(" ")
engine.runAndWait()
def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print(" ")
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"Your Command : {query}\n")
except:
return "None"
return query.lower()
def TaskExe():
while True:
query = takecommand()
if 'hello' in query:
Speak("Hello Sir , How Are You ?")
else:
Speak("No Command Found!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment