forked from ProgrammingHero1/romantic-alexa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
140 lines (117 loc) · 4.1 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
import requests
import os
import psutil
import time
listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', "french")
wikipedia.set_lang("fr")
def bye():
talk('Ok, à bientot')
from sys import exit
exit(0)
def cpu():
usage = str(psutil.cpu_percent())
talk("le cpu est actuellement à " + usage + " %")
def meteo():
url = '' # Open api link here
res = requests.get(url)
data = res.json()
weather = data['weather'][0]['main']
temp = data['main']['temp']
wind_speed = data['wind']['speed']
latitude = data['coord']['lat']
longitude = data['coord']['lon']
description = data['weather'][0]['description']
talk('Temperature : {} degree celcius'.format(temp))
print('Wind Speed : {} m/s'.format(wind_speed))
print('Latitude : {}'.format(latitude))
print('Longitude : {}'.format(longitude))
print('Description : {}'.format(description))
print('weather is: {} '.format(weather))
talk('la météo est : {} '.format(description))
def pendule():
time = datetime.datetime.now().strftime('%H:%M')
talk('il est actuellement ' + time)
def talk(text):
engine.say(text)
engine.runAndWait()
def tanks():
talk("de rien maitre")
def period():
currentH = int(datetime.datetime.now().hour)
year = int(datetime.datetime.now().year)
month = int(datetime.datetime.now().month)
date = int(datetime.datetime.now().day)
time = datetime.datetime.now().strftime('%H:%M')
if currentH >= 0 and currentH < 12:
talk('Bonjour!')
talk("Je m'appelle Alexa , je suis la pour vous aider au quotidien")
print(time + (" ") + str(date) + (" ") + str(month) + (" ") + str(year))
if currentH >= 12 and currentH < 18:
talk('Bonne après-midi!')
talk("Je m'appelle Alexa , je suis la pour vous aider au quotidien")
print(time + (" ") + str(date) + (" ") + str(month) + (" ") + str(year))
if currentH >= 18 and currentH != 0:
talk('Bonsoir!')
talk("Je m'appelle Alexa , je suis la pour vous aider au quotidien")
print(time + (" ") + str(date) + ("/") + str(month) + '/' + str(year))
def take_command():
try:
with sr.Microphone() as source:
print("à l' écoute...")
voice = listener.listen(source)
command = listener.recognize_google(voice, language='fr-FR')
command = command.lower()
if 'alexa' in command:
command = command.replace('alexa', '')
print(command)
except Exception:
pass
return command
def run_alexa():
command = take_command()
print(command)
if 'joue' in command:
song = command.replace('joue', '')
talk('playing ' + song)
pywhatkit.playonyt(song)
elif "qui est" in command:
person = command.replace("qui est", '')
info = wikipedia.summary(person, 1)
print(info)
talk(info)
elif "cpu" in command:
cpu()
elif "météo" in command:
meteo()
elif 'blague' in command:
talk(pyjokes.get_joke('fr'))
elif 'bye' in command:
bye()
elif "donne-moi l'heure" in command:
pendule()
elif "merci" in command:
tanks()
else:
talk("répéter la commande svp")
if __name__ == '__main__':
period()
year = int(datetime.datetime.now().year)
month = int(datetime.datetime.now().month)
date = int(datetime.datetime.now().day)
time = datetime.datetime.now().strftime('%H:%M')
talk("nous sommes le " + str(date) + "jour" + "du mois de " + str(month) + "de l'année " + str(year))
talk("il est actuellement " + time)
print(time + (" ") + str(date) + ("/") + str(month) + '/' + str(year))
print("Alexa is ready")
print(os.getcwd(), os.getpid())
while True:
run_alexa()