-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
39 lines (32 loc) · 1.09 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
import speech_recognition as sr
import pyttsx3
import pywhatkit
hear = sr.Recognizer()
engine = pyttsx3.init()
def intro():
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.say("Hello I'm your assistant, which song will you like to listen")
engine.runAndWait()
return hear
def callAssistant():
try :
with sr.Microphone() as origin:
print("Listening....")
sound = hear.listen(origin)
text = hear.recognize_google(sound)
text = text.lower()
text = text.replace("assistant", '')
if 'play' in text:
print('Please Wait, Playing....')
engine.say("Please Wait, Playing...")
engine.runAndWait()
text = text.replace("play", '')
pywhatkit.playonyt(text)
engine.runAndWait()
except :
print("Microphone is not working or check your internet connection")
engine.say("Microphone is not working or check your internet connection")
engine.runAndWait()
intro()
callAssistant()