-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJUNE.py
More file actions
168 lines (143 loc) · 5.32 KB
/
JUNE.py
File metadata and controls
168 lines (143 loc) · 5.32 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import datetime
import time as time
import pyttsx3
import speech_recognition as sr
import pywhatkit
import pyjokes as pj
import wikipedia as wikipedia
from datetime import datetime as dt
from pathlib import Path
import os
#Getting voice intake ready with voice packages
engine=pyttsx3.init()
voice_intake=sr.Recognizer()
my_mic=sr.Microphone(device_index=1)
voice_intake.energy_threshold = 700
voices = engine.getProperty('voices')
voices = engine.setProperty('voice',voices[2].id)
#Function to read out text to speech
def talk(text):
engine.say(text)
engine.runAndWait()
#Opening line
print(' I am June,your virtual partner,how may i be of service')
talk('I am June, ,your virtual partner, ,how may i be of service')
def command_input():
my_mic=sr.Microphone(device_index=1) #specifying source of input
try:
with my_mic as source:
print("Listening....")
command = voice_intake.listen(source)
command = voice_intake.recognize_google(command)
print("USER INPUT:",command)
command = command.lower()
except Exception:
pass #diff
return command
def run_june():
command=command_input()
if 'diary' in command:
diary()
if "june" in command:
command = command.replace('june', '')
if 'what can you do' in command:
menu()
command=command_input()
if 'diary' in command:
diary()
if 'play' in command:
song = command.replace('play', '')
print('playing' + song)
talk('playing ' + song)
pywhatkit.playonyt(song)
if 'what' and 'time' in command:
Time = datetime.datetime.now().strftime('%I:%M %p')
print('Current time is ' + Time)
talk('Current time is ' + Time)
if 'who is' in command:
person = command.replace('who is', '')
info = wikipedia.summary(person, 1)
print(info)
talk(info)
if "introduce yourself" in command:
intro = "I am a virtual assistant made my Arjun Aravind "
print(intro)
talk(intro)
if "take a break" in command: #hereeeeeeeeeeee
print("Taking a 60 second nap...")
talk("Taking a 60 second nap...")
time.sleep(60)
print('Awake and good to go..')
talk('Awake and good to go..')
if 'joke' in command:
joke = pj.get_joke()
print(joke)
talk(joke)
if "help me" in command:
help_me = 'You got this , do your best and put in the efforts and success will be yours. Take up one idea. ' \
'Make that one idea your life--think of it, dream of it, live on that idea. ' \
'Let the brain, muscles, nerves, every part of your body, be full of that idea, ' \
'and just leave every other idea alone. ' \
'This is the way to success.'
print(help_me)
talk(help_me)
if 'exit' in command:
print("Have a great day,each one's a gift")
talk("Have a great day, ,each one's a gift")
exit()
def menu():
print("Here are some of the things that i can do: \n1.Joke\n2.Music\n3.Diary\n4.Youtube Video\n5.Exit")
talk("Here are some of the things that i can do:Joke , Play Music , Diary , Youtube Video , Exit application")
print("Make your choice:")
talk("Make your choice:")
return
def diary():
print("Would you like to make a new entry or view old entries?")
talk("Would you like to make a new entry or view old entries?") # problem arises after this line
diary_choice = command_input()
engine.runAndWait()
if 'new' in diary_choice:
diary_new_entry()
engine.runAndWait()
elif 'old' in diary_choice:
data_files =os.listdir("D:\AI_PARTNER\Diary_Data")
print("\n\nFiles are ",data_files,sep='\n')
for i,val in enumerate(data_files):
diary_dates=val.split(sep='_')
val_string=("Diary entry ",i," is dated ",diary_dates)
print(val_string)
talk(val_string)
print("Which entry would u like to view?")
talk("Which entry would u like to view?")
ch=command_input()
ch=int(ch)
print("Entry number=",ch)
f=open("D:\AI_PARTNER\Diary_Data\\"+data_files[ch],'r')
diary_data=f.read()
print("Contents of journal log are:\n",diary_data)
talk("Contents of journal log are :")
talk(diary_data)
f.close()
run_june()
def diary_new_entry():
a = dt.now()
cur_date_time = a.strftime("%d_%m_%Y_%H_%M_%S" + ".txt")
data_file = Path("D:\AI_PARTNER\Diary_Data" + '/' + cur_date_time)
print("You may now start to speak your journal entry:")
talk("You may now start to speak your journal entry:")
data_unconfirmed = command_input()
engine.runAndWait()
print(data_unconfirmed)
print("\n Would you like to save this entry or retake the entry?")
talk("\n Would you like to save this entry or retake the entry?")
option = command_input()
engine.runAndWait()
if 'save' in option:
data_confirmed = data_unconfirmed
f = open(data_file, 'a+')
f.write(data_confirmed)
print(f.read())
else:
diary_new_entry()
while True:
run_june()