-
Notifications
You must be signed in to change notification settings - Fork 0
/
botInterface.py
48 lines (38 loc) · 1.45 KB
/
botInterface.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
import speech_recognition as sr
import zulip
import os
# print(os.getcwd())
# get audio from the microphone
while True:
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak:")
audio = r.listen(source)
try:
input_text=r.recognize_google(audio)
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError as e:
print("Could not request results; {0}".format(e))
# Pass the path to your zuliprc file here.
client = zulip.Client(config_file="./zuliprc")
# Send a stream message
request = {
"type": "stream",
"to": "general",
"subject": "general",
"content": "@**Kaleen_Bhayia** "+input_text
}
result = client.send_message(request)
if result['result']!='error':
request = {
'use_first_unread_anchor': True,
'num_before': 0,
'num_after': 1,
'narrow': [{'operator': 'sender', 'operand': '[email protected]'},
{'operator': 'stream', 'operand': 'general'}],
} # type: Dict[str, Any]
result = client.get_messages(request)
print(result)
else:
print('Error in sending the message to the bot!!')