-
Notifications
You must be signed in to change notification settings - Fork 0
/
responder_rhasspy.py
executable file
·56 lines (37 loc) · 1.17 KB
/
responder_rhasspy.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
#!/usr/bin/python
# Marcel Timm, RhinoDevel, 2022jul16
# *** Some notes ***
#
# - Execute BASH "inside" docker environment:
#
# docker exec -it rhasspy bash
import json
import sys
from responder import responder
def get_params(obj):
"""Extract and return (intent) parameters from given object."""
# TODO: This is stupid or not?
#
return json.loads(json.dumps(obj))
def exec_with_obj(obj):
"""Get input from parameter and augment that object with the response."""
intent = obj['intent']['name']
params = get_params(obj)
response = responder.exec(intent, params)
#
# (augments parameters object)
obj['speech'] = {'text': response} # Augments in-/output obj. with response.
def exec_with_str(input_str):
"""Get input from parameter (string) and return response as string."""
ret_val = None
obj = json.loads(input_str)
exec_with_obj(obj)
ret_val = json.dumps(obj)
return ret_val
def exec_with_std():
"""Retrieve input from stdin and send response to stdout."""
input_str = sys.stdin.read()
output_str = exec_with_str(input_str)
print(output_str)
if __name__ == "__main__":
exec_with_std()