-
Notifications
You must be signed in to change notification settings - Fork 0
/
assistant.py
115 lines (103 loc) · 3.73 KB
/
assistant.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
import pyttsx3
import scraper
import tasks
import speech_recognition as sr
import encrypter
import cpu
import music
import os
from cryptography.fernet import Fernet
import webbrowser
import time
from datetime import datetime
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
key = Fernet.generate_key()
f = Fernet(key)
def speak(audio):
engine.say(audio)
engine.runAndWait()
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')
print(f"User said: {query}\n")
except Exception as e:
print(e)
print("Unable to Recognize your voice")
return "None"
return query
def assisstant(command):
if command == str("Open YT"):
scraper.youtube()
speak("Opening Youtube")
if command == str("Open Music app"):
scraper.YT_music()
speak("Opening YT Music")
if command == str("Open Github"):
scraper.Github()
speak("Opening Github")
if command == str("Enter a task = str"):
task_input = input(str("Enter a new task: "))
tasks.text(task_input)
speak("Changes saved")
if command == str("Enter a task = int"):
task_input = input("Enter a new task: ")
task_input_float = int(float(task_input))
tasks.text(task_input_float)
speak("Changes saved")
if command == str("Encrypt"):
encrypter_input = input(str("Enter a string to encrypt: "))
encrypter.encrypt(bytes(encrypter_input, encoding='utf-8'))
# encrypter_input = message
if command == str("Decrypt"):
decrypter_input = input(str("Enter to decrypt: "))
encrypter.decrypt(bytes(decrypter_input, encoding='utf-8'))
if command == str("Play some music"):
music_choice = input(str("Should I open YT Music or Play locally?"))
if music_choice == str("Play from YT Music"):
scraper.YT_music()
elif music_choice == str("Play Locally"):
# pick an external mp3 player you have
music.play_music("/home/atif/Documents/MyProjects/Assistant/Music/Post Malone - Better Now.mp3")
# command_input = input("Enter command: ")
# assisstant(command_input)
if __name__ == "__main__":
clear = lambda: os.system('cls')
clear()
while True:
query = takeCommand().lower()
if 'music' in query:
speak("Do you want to YT Music or play locally")
if 'locally' in query:
pass
elif 'music' in query:
webbrowser.open("music.youtube.com")
elif 'youtube' in query:
speak("Opening Youtube")
webbrowser.open("youtube.com")
elif 'github' in query:
webbrowser.open("https://github.com/AtifUsmani/Assistant")
elif 'new string' in query:
speak("Plz enter what you want to encrypt")
task_string = input(str("Plz enter what you want to encrypt: "))
tasks.text(task_string)
speak("Changes saved")
elif 'new integer' in query:
speak("Plz enter what you want to encrypt")
task_input = input("Enter a new task: ")
task_input_float = int(float(task_input))
tasks.text(task_input_float)
speak("Changes saved")
elif 'time' in query:
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print("Current Time =", current_time)
speak_current_time = ("Current Time =", current_time)
speak(speak_current_time)