Advertisement
sourav8256

Untitled

Sep 9th, 2020
1,521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. import speech_recognition as sr
  2. import pyttsx3
  3. import os
  4.  
  5. engine = pyttsx3.init()
  6. r = sr.Recognizer()
  7.  
  8. print("Please Talk")
  9.  
  10.  
  11.  
  12. with sr.Microphone() as source:
  13.     r.adjust_for_ambient_noise(source)
  14.  
  15.  
  16.     while True:
  17.         #print(sr.Microphone())
  18.         #audio_data=r.record(source,duration=5)
  19.         audio_data = r.listen(source)
  20.         #audio_data = r.adjust_for_ambient_noise(source, duration=5)
  21.         print("Recognizing...")
  22.         text = ""
  23.         try:
  24.             text = r.recognize_google(audio_data)
  25.         except:
  26.             print("## could not recognize")
  27.             #print("")
  28.         print(text)
  29.         if "hello Jarvis" in text:
  30.             print("Hello Sourav")
  31.             engine.say("Hello Sourav")
  32.             engine.runAndWait()
  33.        
  34.         if "open" in text.lower() and "chrome" in text.lower():
  35.             print("Opening chrome...")
  36.             engine.say("Opening chrome...")
  37.             engine.runAndWait()
  38.             os.system("\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"")
  39.  
  40.         if "stop"==text:
  41.             break        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement