-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
60 lines (40 loc) · 1.57 KB
/
main.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
import websockets
import requests
import json
import logging
import i18n
i18n.load_path.append('./rhino/modules/translations')
import rhino
import yaml
with open('./rhino/settings.yml', 'r') as file:
settings = yaml.safe_load(file)
i18n.set('locale', settings['general']['language'])
i18n.set('fallback', 'en')
rhasspy_websocket = settings['rhasspy']['websocket_url']+'/api/events/intent'
async def websocket_loop():
while True:
async with websockets.connect(rhasspy_websocket) as websocket:
recv = await websocket.recv()
jsonstring = json.loads(recv)
siteId = jsonstring["siteId"]
intent = jsonstring["intent"]["name"]
logging.info(f"JSON: {recv}")
logging.info(f"Intent: |{intent}|")
print(f"JSON: {recv}")
print(f"Intent: |{intent}|")
if intent != "" and rhino.modules.answers.getAnswer(jsonstring) == 0:
if hasattr(rhino.ext_modules, intent):
try:
externalFunction = getattr(rhino.ext_modules, intent)
externalFunction(jsonstring, siteId)
except AttributeError as e:
rhino.modules.rhasspy.speak(i18n.t('translations.errors.no_skill'), siteId)
else:
rhino.modules.rhasspy.speak(i18n.t('translations.errors.no_skill'), siteId)
if __name__ == "__main__":
logging.info("Started")
print("Started")
asyncio.run(websocket_loop())