-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlexa.py
36 lines (34 loc) · 896 Bytes
/
Alexa.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
import speech_recognition as sr
import pyaudio
import pyttsx3
import pywhatkit
#import dateti
listner=sr.Recognizer()
engine=pyttsx3.init()
voices=engine.getProperty('voices')
engine.setProperty('voice',voices[1].id)
def talk(text):
engine.say(text)
engine.runAndWait()
def take_command():
command = ""
try:
with sr.Microphone() as source:
print ('listening...')
voice=listner.listen(source)
command=listner.recognize_google(voice)
command=command.lower()
if 'alexa' in command:
command=command.replace('alexa','')
print(command)
except:
pass
return command
def run_alexa():
command=take_command()
print(command)
if 'play' in command:
song=command.replace('play','')
talk('playing' + song)
pywhatkit.playonyt(song)
run_alexa()