-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathresponse.py
84 lines (71 loc) · 2.51 KB
/
response.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
"""
This file process converted text and perform actions accordingly.
This file can be extended with more action.
"""
import valib as va
import action as a
import time
import logging
logger = logging.getLogger('voice assistant')
def process_text(text, pa):
"""
asking who are you?
"""
if "who are you" in text:
va.audio_playback("i am a i voice assistant system")
"""
asking about weather information.
"""
if "weather" in text:
va.audio_playback("which city")
time.sleep(0.5)
file_name = pa.process(3)
city = pa.voice_command_processor(file_name)
logger.info("process_text : City :: " + city)
try:
humidity, temp, phrase = a.weatherReport(city)
va.audio_playback(
"currently in " + city + " temperature is " + str(temp) + " degree celsius, " + "humidity is " + str(
humidity) + " percent and sky is " + phrase)
logger.info("currently in " + city + " temperature is " + str(temp) + "degree celsius, " + "humidity is " + str(
humidity) + " percent and sky is " + phrase)
except KeyError as e:
va.audio_playback("sorry, i couldn't get the location")
"""
asking for search somthing like:
what is raspberry pi
who is isac newton etc.
"""
if "search" in text or "Search" in text:
va.audio_playback("tell me what to search")
time.sleep(0.5)
file_name = pa.process(5)
search_data = pa.voice_command_processor(file_name)
try:
result = a.google_search(search_data)
if result:
va.audio_playback(result)
else:
va.audio_playback("sorry, i couldn't find any result for " + search_data)
except KeyError as e:
va.audio_playback("sorry, i couldn't find any result for " + search_data)
pass
"""
asking aboout current time.
"""
if "time" in text or "Time" in text:
current_time = a.current_datetime("time")
va.audio_playback("right now it is " + current_time)
"""
asking about today's date.
"""
if "date" in text or "Date" in text:
date = a.current_datetime("date")
va.audio_playback("today it is " + date)
"""
asking for rebooting the voice assistant system.
"""
if "reboot" in text or "Reboot" in text:
va.audio_playback("ok.. rebooting the server")
a.reboot_server()
return "done"