-
Notifications
You must be signed in to change notification settings - Fork 0
/
aisstant_IA.py
83 lines (69 loc) · 2.31 KB
/
aisstant_IA.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
import pyttsx3 #pip install pyttsx3 no necesary internet
import datetime
import speech_recognition as sr #pip install SpeechRecognition
import pyaudio #pip install pyaudio
import os
import random
engine = pyttsx3.init()
engine.setProperty('rate', 180) # Velocidad de habla
engine.setProperty('volume', 0.9) # Volumen de la voz
voices = engine.getProperty('voices') # Lista de voces disponibles
engine.setProperty('voice', voices[1].id) # Cambiar a la segunda voz disponible
text = "Hello, I am IA asistant"
def speak(text):
engine.say(text)
engine.runAndWait()
#speak(text)
def time():
time = datetime.datetime.now().strftime("%I:%M: %p")
speak(f"The time is {time}")
#time()
def date():
day = int(datetime.datetime.now().day)
month= int(datetime.datetime.now().month)
year= int(datetime.datetime.now().year)
speak(f"The date is, day {day}, of the month {month}, of the year {year}")
#date()
def play_song():
songs_dir = "C:\\Users\\User\\Music" #forlder where save your songs
songs = os.listdir(songs_dir)
song_choice = random.choice(songs)
os.startfile(os.path.join(songs_dir, song_choice))
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in') # lenguague english "in"
#query = r.recognize_google(audio, language='es-ES') # lenguague spanish
print(f"User said: {query}\n")
except Exception as e:
print(e)
print("Say that again please...")
return "None"
return query
#takeCommand()
""" def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('email', 'password')
server.sendmail('email', to, content)
server.close() """
if __name__ == "__main__":
#time() fuction for start
speak("Hello sir , say me your instructions")
while True:
query = takeCommand().lower()
if 'time' in query:
time()
elif 'date' in query:
date()
elif 'play song' in query:
play_song()
elif 'offline' in query:
speak("I am offline")
quit()