-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathenglish_voice_assistant.rb
301 lines (263 loc) · 8.84 KB
/
english_voice_assistant.rb
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
require 'open-uri'
require 'nokogiri'
def open_weather_report(city)
puts "Opening the weather report for #{city}."
begin
doc = Nokogiri::HTML(URI.open("https://www.weather-forecast.com/locations/#{city}/forecasts/latest"))
weather_elements = doc.css(".b-forecast__table-description-content")
weather_elements.each do |element|
puts element.text.strip
end
rescue StandardError => e
puts "Failed to fetch weather information. Please try again later."
end
end
def father_of_the_nation_of_bangladesh
puts "The Father of the Nation Bangabandhu Sheikh Mujibur Rahman is the architect of independent Bangladesh."
puts "He played a vital role in the liberation movement and is revered as a national hero."
end
def get_ip_address
begin
ip_address = URI.open("https://checkip.amazonaws.com").read
puts "Your IP address is: #{ip_address}"
rescue StandardError => e
puts "Failed to retrieve IP address. Please try again later."
end
end
def open_wikipedia
begin
system("start https://www.wikipedia.org/")
rescue StandardError => e
puts "Failed to open Wikipedia. Please try again later."
end
end
def search_on_wikipedia
puts "What would you like to search on Wikipedia?"
query = gets.chomp
begin
system("start https://en.wikipedia.org/wiki/#{query}")
rescue StandardError => e
puts "Failed to search on Wikipedia. Please try again later."
end
end
def search_on_youtube
puts "What would you like to search on YouTube?"
query = gets.chomp
begin
system("start https://www.youtube.com/results?search_query=#{query}")
rescue StandardError => e
puts "Failed to search on YouTube. Please try again later."
end
end
def play_on_youtube
puts "What would you like to play on YouTube?"
query = gets.chomp
begin
system("start https://www.youtube.com/results?search_query=#{query}")
rescue StandardError => e
puts "Failed to play on YouTube. Please try again later."
end
end
def open_youtube
begin
system("start https://www.youtube.com/")
rescue StandardError => e
puts "Failed to open YouTube. Please try again later."
end
end
def get_date_and_time
current_date_time = Time.now.strftime("%d-%m-%Y %H:%M:%S")
puts "The current date and time is: #{current_date_time}"
end
def get_local_time
current_time = Time.now.strftime("%H:%M:%S")
puts "The current local time is: #{current_time}"
end
def get_today_date
today_date = Time.now.strftime("%d-%m-%Y")
puts "Today's date is: #{today_date}"
end
def open_facebook
begin
system("start https://www.facebook.com/")
rescue StandardError => e
puts "Failed to open Facebook. Please try again later."
end
end
def open_facebook_profile
begin
system("start https://www.facebook.com/profile.php")
rescue StandardError => e
puts "Failed to open Facebook profile. Please try again later."
end
end
def open_facebook_settings
begin
system("start https://www.facebook.com/settings")
rescue StandardError => e
puts "Failed to open Facebook settings. Please try again later."
end
end
def open_facebook_reel
begin
system("start https://www.facebook.com/reels")
rescue StandardError => e
puts "Failed to open Facebook Reels. Please try again later."
end
end
def open_facebook_messenger
begin
system("start https://www.messenger.com/")
rescue StandardError => e
puts "Failed to open Facebook Messenger. Please try again later."
end
end
def open_facebook_video
begin
system("start https://www.facebook.com/videos")
rescue StandardError => e
puts "Failed to open Facebook videos. Please try again later."
end
end
def open_facebook_notification
begin
system("start https://www.facebook.com/notifications")
rescue StandardError => e
puts "Failed to open Facebook notifications. Please try again later."
end
end
def open_google_browser
begin
system("start https://www.google.com/")
rescue StandardError => e
puts "Failed to open Google. Please try again later."
end
end
def open_google_mail
begin
system("start https://mail.google.com/")
rescue StandardError => e
puts "Failed to open Google Mail. Please try again later."
end
end
def open_google_earth
begin
system("start https://www.google.com/earth/")
rescue StandardError => e
puts "Failed to open Google Earth. Please try again later."
end
end
def google_earth_specify_city
puts "Which city do you want to see on Google Earth?"
city = gets.chomp.downcase
begin
system("start https://www.google.com/earth/geo/#{city}/")
rescue StandardError => e
puts "Failed to open Google Earth for the specified city. Please try again later."
end
end
def open_google_map
begin
system("start https://www.google.com/maps/")
rescue StandardError => e
puts "Failed to open Google Map. Please try again later."
end
end
def google_map_specify_city
puts "Which city do you want to see on Google Map?"
city = gets.chomp.downcase
begin
system("start https://www.google.com/maps/place/#{city}/")
rescue StandardError => e
puts "Failed to open Google Map for the specified city. Please try again later."
end
end
def google_translate_specify_word
puts "Which word or sentence do you want to translate to English?"
text = gets.chomp
begin
system("start https://translate.google.com/#auto/en/#{text}")
rescue StandardError => e
puts "Failed to open Google Translate. Please try again later."
end
end
def tell_joke
begin
doc = Nokogiri::HTML(URI.open("https://www.jokes4us.com/miscellaneousjokes/cleanjokes.html"))
joke_elements = doc.css("div[style='font-size:medium;']")
joke_elements.each do |element|
puts element.text.strip
end
rescue StandardError => e
puts "Failed to fetch a joke. Please try again later."
end
end
def translate_languages
puts "Which language do you want to translate from?"
from_language = gets.chomp.downcase
puts "Which language do you want to translate to?"
to_language = gets.chomp.downcase
puts "What do you want to translate?"
text = gets.chomp
begin
system("start https://translate.google.com/##{from_language}/#{to_language}/#{text}")
rescue StandardError => e
puts "Failed to open Google Translate. Please try again later."
end
end
def available_commands
puts "Available commands:"
puts "- Weather: Get the weather report of a city"
puts "- Father of the Nation of Bangladesh: Learn about the Father of the Nation of Bangladesh"
puts "- IP address: Get your IP address"
puts "- Opening Wikipedia: Open the Wikipedia homepage"
puts "- Search on Wikipedia: Search for a specific topic on Wikipedia"
puts "- Search on YouTube: Search for a video on YouTube"
puts "- Play on YouTube: Search and play a video on YouTube"
puts "- Open YouTube: Open the YouTube homepage"
puts "- Date and Time: Get the current date and time"
puts "- Today's Time: Get the current local time"
puts "- Today's Date: Get today's date"
puts "- Opening Facebook: Open the Facebook homepage"
puts "- Facebook Profile: Open your Facebook profile"
puts "- Facebook Settings: Open the Facebook settings page"
puts "- Facebook Reels: Open Facebook Reels"
puts "- Facebook Messenger: Open Facebook Messenger"
puts "- Facebook Video: Open Facebook videos"
puts "- Facebook Notification: Open Facebook notifications"
puts "- Opening Google: Open the Google homepage"
puts "- Opening Gmail: Open Google Mail"
puts "- Google Earth: Open Google Earth"
puts "- Google City: View a city on Google Earth"
puts "- Google Map: Open Google Map"
puts "- City from Map: View a city on Google Map"
puts "- Translate to English: Translate a word or sentence to English"
puts "- Listen a Joke: Listen to a joke"
puts "- Translation between two languages: Translate text between two languages"
puts "- What can you do: Get the list of available commands"
puts "- Who made you: Know who made this digital assistant"
puts "- What is your name: Know the name of this digital assistant"
puts "- Ask: Ask a computational or geographical question"
end
def who_made_you
puts "I was created by a team of developers."
end
def what_is_your_name
puts "My name is Digital Assistant."
end
def computational_geographical_question
puts "Please ask your question:"
question = gets.chomp
puts "Sorry, I'm unable to answer computational or geographical questions at the moment."
end
puts "Sk. Salahuddin - Khulna"
loop do
puts "How may I assist you?"
user_command = gets.chomp.downcase
break if user_command.include?("exit") || user_command.include?("close") || user_command.include?("off") ||
user_command.include?("good bye") || user_command.include?("bye") || user_command.include?("ok bye") ||
user_command.include?("turn off") || user_command.include?("shutdown") || user_command.include?("no thanks") ||
user_command.include?("stop")
puts "Please wait"
perform_action(user_command)
end