-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnips_common.py
More file actions
39 lines (33 loc) · 1.36 KB
/
snips_common.py
File metadata and controls
39 lines (33 loc) · 1.36 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
import mqtt_client, json, uuid
import paho.mqtt.publish as paho_publisher
try:
from hermes_python.ffi.utils import MqttOptions
except ImportError:
None
def get_session_id(intent_message):
return intent_message.session_id
def get_site_id(intent_message):
return intent_message.site_id
def get_intent_name(intent_message):
return intent_message.intent.intent_name.split(':')[-1]
def get_hermes_mqtt_options():
return MqttOptions(username = mqtt_client.get_user(), password = mqtt_client.get_pass(), broker_address = mqtt_client.get_addr_port())
def put_notification(site_id, text):
data = {}
data['siteId'] = site_id
data['init'] = {}
data['init']['type'] = 'notification'
data['init']['text'] = text
json_data = json.dumps(data)
mqtt_client.put('hermes/dialogueManager/startSession', str(json_data))
def play_sound(site_id, file, play_id = None):
if play_id is None:
play_id = site_id + "-" + str(uuid.uuid1())
mqtt_user = mqtt_client.get_user()
if len(mqtt_user) > 0:
auth = {'username': mqtt_user, 'password': mqtt_client.get_pass()}
else:
auth = {}
binaryFile = open(file, 'rb')
wav = bytearray(binaryFile.read())
paho_publisher.single("hermes/audioServer/{}/playBytes/{}".format(site_id, play_id), wav, hostname = mqtt_client.get_addr(), port = mqtt_client.get_port(), auth = auth)