-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
51 lines (47 loc) · 1.71 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import speech_recognition as sr
import datetime
import subprocess
import pywhatkit
import pyttsx3
import webbrowser
from keyboard import press_and_release
engine=pyttsx3.init() # text to sppech process
voices=engine.getProperty('voices') # voices used to communicate
engine.setProperty('voice',voices[1].id) # female voice=1,male voice=0
recognizer=sr.Recognizer()
def cmd(): # function declaration
with sr.Microphone() as source: # accessing the microphone of laptop
print("Clearing background noises..Pleasw wait!!")
recognizer.adjust_for_ambient_noise(source,duration=0.5) # clearing the backgroung noise
print('Ask me anything..')
recordedaudio=recognizer.listen(source) # recording the voice to give command
try:
text=recognizer.recognize_google(recordedaudio,language='en_US') # google recognizer is used to convert text to speech
text=text.lower()
print('Your message:',format(text))
except Exception as ex:
print(ex)
if 'chrome' in text:
a='opening chrome'
engine.say(a)
engine.runAndWait()
programName = "C:\Program Files\Google\Chrome\Application\chrome.exe"
subprocess.Popen([programName])
press_and_release("ctrl + w")
if 'time' in text:
time = datetime.datetime.now().strftime('%I:%M %p')
print(time)
engine.say(time)
engine.runAndWait()
if 'play' in text:
a='opening youtube..'
engine.say(a)
engine.runAndWait()
pywhatkit.playonyt(text)
if 'youtube' in text:
b='opening youtube'
engine.say(b)
engine.runAndWait()
webbrowser.open('www.youtube.com')
while True:
cmd()