-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathengilsh_voice_assistant.java
413 lines (375 loc) · 19.6 KB
/
engilsh_voice_assistant.java
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
import java.util.Scanner;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.awt.Desktop;
import java.net.URI;
import java.net.URISyntaxException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class DigitalAssistant {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Sk. Salahuddin - Khulna");
while (true) {
System.out.println("How may I assist you?");
String userCommand = scanner.nextLine().toLowerCase();
if (userCommand.contains("exit") || userCommand.contains("close") || userCommand.contains("off") ||
userCommand.contains("good bye") || userCommand.contains("bye") || userCommand.contains("ok bye") ||
userCommand.contains("turn off") || userCommand.contains("shutdown") || userCommand.contains("no thanks") ||
userCommand.contains("stop")) {
System.out.println("Assistant Shut Down");
System.out.println("Take care and see you later");
break;
}
System.out.println("Please wait");
performAction(userCommand);
}
}
public static void performAction(String userCommand) {
if (userCommand.contains("weather") || userCommand.contains("weather report") || userCommand.contains("today's weather report")) {
System.out.println("Sure, which city?");
Scanner scanner = new Scanner(System.in);
String city = scanner.nextLine().toLowerCase();
openWeatherReport(city);
} else if (userCommand.contains("bangabandhu sheikh mujibur rahman") || userCommand.contains("bangabandhu") ||
userCommand.contains("sheikh mujibur rahman") || userCommand.contains("father of the nation of bangladesh") ||
userCommand.contains("father of the nation")) {
fatherOfTheNationOfBangladesh();
} else if (userCommand.contains("ip address") || userCommand.contains("internet protocol") || userCommand.contains("ip")) {
getIPAddress();
} else if (userCommand.contains("opening wikipedia")) {
openWikipedia();
} else if (userCommand.contains("search on wikipedia")) {
searchOnWikipedia();
} else if (userCommand.contains("search on youtube")) {
searchOnYouTube();
} else if (userCommand.contains("play on youtube") || userCommand.contains("play from youtube") ||
userCommand.contains("play a song from youtube") || userCommand.contains("play a movie from youtube") ||
userCommand.contains("play something on youtube") || userCommand.contains("play something from youtube")) {
playOnYouTube();
} else if (userCommand.contains("open youtube") || userCommand.contains("opening youtube")) {
openYouTube();
} else if (userCommand.contains("date and time")) {
getDateAndTime();
} else if (userCommand.contains("today's time") || userCommand.contains("local time") || userCommand.contains("time")) {
getLocalTime();
} else if (userCommand.contains("today's date") || userCommand.contains("today date") || userCommand.contains("date")) {
getTodayDate();
} else if (userCommand.contains("opening facebook")) {
openFacebook();
} else if (userCommand.contains("facebook profile")) {
openFacebookProfile();
} else if (userCommand.contains("facebook settings")) {
openFacebookSettings();
} else if (userCommand.contains("facebook reels")) {
openFacebookReel();
} else if (userCommand.contains("facebook messenger")) {
openFacebookMessenger();
} else if (userCommand.contains("facebook video")) {
openFacebookVideo();
} else if (userCommand.contains("facebook notification")) {
openFacebookNotification();
} else if (userCommand.contains("opening google")) {
openGoogleBrowser();
} else if (userCommand.contains("opening gmail")) {
openGoogleMail();
} else if (userCommand.contains("google earth")) {
openGoogleEarth();
} else if (userCommand.contains("google city") || userCommand.contains("city on google") ||
userCommand.contains("city from earth") || userCommand.contains("city on earth")) {
googleEarthSpecifyCity();
} else if (userCommand.contains("google map") || userCommand.contains("map") || userCommand.contains("map on google")) {
openGoogleMap();
} else if (userCommand.contains("city from map") || userCommand.contains("map city") ||
userCommand.contains("city on map") || userCommand.contains("google map city")) {
googleMapSpecifyCity();
} else if (userCommand.contains("translate to english") || userCommand.contains("translate into english") ||
userCommand.contains("word translate") || userCommand.contains("translate a sentence")) {
googleTranslateSpecifyWord();
} else if (userCommand.contains("listen a joke") || userCommand.contains("tell me a joke")) {
tellJoke();
} else if (userCommand.contains("translation between two language") || userCommand.contains("translated language") ||
userCommand.contains("translate from google") || userCommand.contains("language translation") ||
userCommand.contains("language")) {
translateLanguages();
} else if (userCommand.contains("what can you do") || userCommand.contains("available commands") || userCommand.contains("help")) {
availableCommands();
} else if (userCommand.contains("who made you")) {
whoMadeYou();
} else if (userCommand.contains("what is your name") || userCommand.contains("your name")) {
whatIsYourName();
} else if (userCommand.contains("ask")) {
computationalGeographicalQuestion();
} else {
System.out.println("Sorry, I didn't understand that command. Please try again!");
}
}
public static void openWeatherReport(String city) {
System.out.println("Opening the weather report for " + city + ".");
try {
Document doc = Jsoup.connect("https://www.weather-forecast.com/locations/" + city + "/forecasts/latest").get();
Elements weatherElements = doc.select(".b-forecast__table-description-content");
for (Element element : weatherElements) {
System.out.println(element.text());
}
} catch (IOException e) {
System.out.println("Failed to fetch weather information. Please try again later.");
}
}
public static void fatherOfTheNationOfBangladesh() {
System.out.println("The Father of the Nation Bangabandhu Sheikh Mujibur Rahman is the architect of independent Bangladesh.");
System.out.println("He played a vital role in the liberation movement and is revered as a national hero.");
}
public static void getIPAddress() {
try {
Document doc = Jsoup.connect("https://checkip.amazonaws.com").get();
String ipAddress = doc.body().text();
System.out.println("Your IP address is: " + ipAddress);
} catch (IOException e) {
System.out.println("Failed to retrieve IP address. Please try again later.");
}
public static void openWikipedia() {
try {
Desktop.getDesktop().browse(new URI("https://www.wikipedia.org/"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Wikipedia. Please try again later.");
}
}
public static void searchOnWikipedia() {
Scanner scanner = new Scanner(System.in);
System.out.println("What would you like to search on Wikipedia?");
String query = scanner.nextLine();
try {
Desktop.getDesktop().browse(new URI("https://en.wikipedia.org/wiki/" + query));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to search on Wikipedia. Please try again later.");
}
}
public static void searchOnYouTube() {
Scanner scanner = new Scanner(System.in);
System.out.println("What would you like to search on YouTube?");
String query = scanner.nextLine();
try {
Desktop.getDesktop().browse(new URI("https://www.youtube.com/results?search_query=" + query));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to search on YouTube. Please try again later.");
}
}
public static void playOnYouTube() {
Scanner scanner = new Scanner(System.in);
System.out.println("What would you like to play on YouTube?");
String query = scanner.nextLine();
try {
Desktop.getDesktop().browse(new URI("https://www.youtube.com/results?search_query=" + query));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to play on YouTube. Please try again later.");
}
}
public static void openYouTube() {
try {
Desktop.getDesktop().browse(new URI("https://www.youtube.com/"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open YouTube. Please try again later.");
}
}
public static void getDateAndTime() {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
Date currentDate = Calendar.getInstance().getTime();
String dateTime = dateFormat.format(currentDate);
System.out.println("The current date and time is: " + dateTime);
}
public static void getLocalTime() {
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
Date currentTime = Calendar.getInstance().getTime();
String localTime = timeFormat.format(currentTime);
System.out.println("The current local time is: " + localTime);
}
public static void getTodayDate() {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date currentDate = Calendar.getInstance().getTime();
String todayDate = dateFormat.format(currentDate);
System.out.println("Today's date is: " + todayDate);
}
public static void openFacebook() {
try {
Desktop.getDesktop().browse(new URI("https://www.facebook.com/"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Facebook. Please try again later.");
}
}
public static void openFacebookProfile() {
try {
Desktop.getDesktop().browse(new URI("https://www.facebook.com/profile.php"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Facebook profile. Please try again later.");
}
}
public static void openFacebookSettings() {
try {
Desktop.getDesktop().browse(new URI("https://www.facebook.com/settings"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Facebook settings. Please try again later.");
}
}
public static void openFacebookReel() {
try {
Desktop.getDesktop().browse(new URI("https://www.facebook.com/reels"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Facebook Reels. Please try again later.");
}
}
public static void openFacebookMessenger() {
try {
Desktop.getDesktop().browse(new URI("https://www.messenger.com/"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Facebook Messenger. Please try again later.");
}
}
public static void openFacebookVideo() {
try {
Desktop.getDesktop().browse(new URI("https://www.facebook.com/videos"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Facebook videos. Please try again later.");
}
}
public static void openFacebookNotification() {
try {
Desktop.getDesktop().browse(new URI("https://www.facebook.com/notifications"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Facebook notifications. Please try again later.");
}
}
public static void openGoogleBrowser() {
try {
Desktop.getDesktop().browse(new URI("https://www.google.com/"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Google. Please try again later.");
}
}
public static void openGoogleMail() {
try {
Desktop.getDesktop().browse(new URI("https://mail.google.com/"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Google Mail. Please try again later.");
}
}
public static void openGoogleEarth() {
try {
Desktop.getDesktop().browse(new URI("https://www.google.com/earth/"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Google Earth. Please try again later.");
}
}
public static void googleEarthSpecifyCity() {
Scanner scanner = new Scanner(System.in);
System.out.println("Which city do you want to see on Google Earth?");
String city = scanner.nextLine().toLowerCase();
try {
Desktop.getDesktop().browse(new URI("https://www.google.com/earth/geo/" + city + "/"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Google Earth for the specified city. Please try again later.");
}
}
public static void openGoogleMap() {
try {
Desktop.getDesktop().browse(new URI("https://www.google.com/maps/"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Google Map. Please try again later.");
}
}
public static void googleMapSpecifyCity() {
Scanner scanner = new Scanner(System.in);
System.out.println("Which city do you want to see on Google Map?");
String city = scanner.nextLine().toLowerCase();
try {
Desktop.getDesktop().browse(new URI("https://www.google.com/maps/place/" + city + "/"));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Google Map for the specified city. Please try again later.");
}
}
public static void googleTranslateSpecifyWord() {
Scanner scanner = new Scanner(System.in);
System.out.println("Which word or sentence do you want to translate to English?");
String text = scanner.nextLine();
try {
Desktop.getDesktop().browse(new URI("https://translate.google.com/#auto/en/" + text));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Google Translate. Please try again later.");
}
}
public static void tellJoke() {
try {
Document doc = Jsoup.connect("https://www.jokes4us.com/miscellaneousjokes/cleanjokes.html").get();
Elements jokeElements = doc.select("div[style='font-size:medium;']");
for (Element element : jokeElements) {
System.out.println(element.text());
}
} catch (IOException e) {
System.out.println("Failed to fetch a joke. Please try again later.");
}
}
public static void translateLanguages() {
Scanner scanner = new Scanner(System.in);
System.out.println("Which language do you want to translate from?");
String fromLanguage = scanner.nextLine().toLowerCase();
System.out.println("Which language do you want to translate to?");
String toLanguage = scanner.nextLine().toLowerCase();
System.out.println("What do you want to translate?");
String text = scanner.nextLine();
try {
Desktop.getDesktop().browse(new URI("https://translate.google.com/#" + fromLanguage + "/" + toLanguage + "/" + text));
} catch (IOException | URISyntaxException e) {
System.out.println("Failed to open Google Translate. Please try again later.");
}
}
public static void availableCommands() {
System.out.println("Available commands:");
System.out.println("- Weather: Get the weather report of a city");
System.out.println("- Bangabandhu Sheikh Mujibur Rahman: Learn about the Father of the Nation of Bangladesh");
System.out.println("- IP address: Get your IP address");
System.out.println("- Opening Wikipedia: Open the Wikipedia homepage");
System.out.println("- Search on Wikipedia: Search for a specific topic on Wikipedia");
System.out.println("- Search on YouTube: Search for a video on YouTube");
System.out.println("- Play on YouTube: Search and play a video on YouTube");
System.out.println("- Open YouTube: Open the YouTube homepage");
System.out.println("- Date and Time: Get the current date and time");
System.out.println("- Today's Time: Get the current local time");
System.out.println("- Today's Date: Get today's date");
System.out.println("- Opening Facebook: Open the Facebook homepage");
System.out.println("- Facebook Profile: Open your Facebook profile");
System.out.println("- Facebook Settings: Open the Facebook settings page");
System.out.println("- Facebook Reels: Open Facebook Reels");
System.out.println("- Facebook Messenger: Open Facebook Messenger");
System.out.println("- Facebook Video: Open Facebook videos");
System.out.println("- Facebook Notification: Open Facebook notifications");
System.out.println("- Opening Google: Open the Google homepage");
System.out.println("- Opening Gmail: Open Google Mail");
System.out.println("- Google Earth: Open Google Earth");
System.out.println("- Google City: View a city on Google Earth");
System.out.println("- Google Map: Open Google Map");
System.out.println("- City from Map: View a city on Google Map");
System.out.println("- Translate to English: Translate a word or sentence to English");
System.out.println("- Listen a Joke: Listen to a joke");
System.out.println("- Translation between two languages: Translate text between two languages");
System.out.println("- What can you do: Get the list of available commands");
System.out.println("- Who made you: Know who made this digital assistant");
System.out.println("- What is your name: Know the name of this digital assistant");
System.out.println("- Ask: Ask a computational or geographical question");
}
public static void whoMadeYou() {
System.out.println("I was created by Sk. Salahuddin from Khulna, Bangladesh.");
}
public static void whatIsYourName() {
System.out.println("My name is Digital Assistant.");
}
public static void computationalGeographicalQuestion() {
Scanner scanner = new Scanner(System.in);
System.out.println("Please ask your question:");
String question = scanner.nextLine();
System.out.println("Sorry, I'm unable to answer computational or geographical questions at the moment.");
}
}