|
|
@@ -24,76 +24,68 @@ import java.util.stream.Collectors;
|
|
24
|
24
|
public class EslEventListenerAsr implements IEslEventListener {
|
|
25
|
25
|
@Override
|
|
26
|
26
|
public void eventReceived(EslEvent event) {
|
|
27
|
|
-
|
|
28
|
27
|
String eventname = event.getEventName();
|
|
29
|
|
-
|
|
30
|
28
|
Map<String, String> header = event.getEventHeaders();
|
|
31
|
|
- if (eventname.equals("CUSTOM")) {
|
|
32
|
|
- String subclass = header.get("Event-Subclass").replace("::", "_").toLowerCase();
|
|
33
|
|
- switch (EslEventEnum.valueOf(subclass)) {
|
|
34
|
|
- case mod_funasr_json:
|
|
35
|
|
- //不是机器人,不是自动外呼
|
|
36
|
|
- if (!(header.containsKey("Caller-Context") && header.get("Caller-Context").equals("robot"))) {
|
|
37
|
|
- if (!(header.containsKey("variable_call_type") && header.get("variable_call_type").equals("3"))) {
|
|
38
|
|
- String asrs = header.get("funasr_result");
|
|
39
|
|
- Map asr = JSON.parseObject(asrs, Map.class);
|
|
40
|
|
- if (asr.containsKey("mode") && asr.get("mode").toString().equals("2pass-offline")) {
|
|
41
|
|
- String text = asr.get("text").toString();
|
|
42
|
|
- if (StringHelper.isNotEmpty(text)) {
|
|
43
|
|
- String[] chanNames = header.get("Channel-Name").split("@")[0].split("/");
|
|
44
|
|
- Channel chan2 = EslCommon.getChanByNumber(chanNames[2]);
|
|
45
|
|
- if (chan2 != null) sendAsr(chan2, text,asr.get("timestamp"));
|
|
46
|
|
- }
|
|
|
29
|
+ //不是机器人,不是自动外呼
|
|
|
30
|
+ if (!(header.containsKey("variable_robot") && header.get("variable_robot").equals("1")) &&
|
|
|
31
|
+ !(header.containsKey("variable_call_type") && header.get("variable_call_type").equals("3"))) {
|
|
|
32
|
+ if (eventname.equals("CUSTOM")) {
|
|
|
33
|
+ String subclass = header.get("Event-Subclass").replace("::", "_").toLowerCase();
|
|
|
34
|
+ switch (EslEventEnum.valueOf(subclass)) {
|
|
|
35
|
+ case mod_funasr_json:
|
|
|
36
|
+ String asrs = header.get("funasr_result");
|
|
|
37
|
+ Map asr = JSON.parseObject(asrs, Map.class);
|
|
|
38
|
+ if (asr.containsKey("mode") && asr.get("mode").toString().equals("2pass-offline")) {
|
|
|
39
|
+ String text = asr.get("text").toString();
|
|
|
40
|
+ if (StringHelper.isNotEmpty(text)) {
|
|
|
41
|
+ String[] chanNames = header.get("Channel-Name").split("@")[0].split("/");
|
|
|
42
|
+ Channel chan2 = EslCommon.getChanByNumber(chanNames[2]);
|
|
|
43
|
+ if (chan2 != null) sendAsr(chan2, text, asr.get("timestamp"));
|
|
47
|
44
|
}
|
|
48
|
45
|
}
|
|
49
|
|
- }
|
|
50
|
|
- break;
|
|
51
|
|
- }
|
|
52
|
|
- } else {
|
|
53
|
|
- EslClientService eslClientService = SpringHelper.getBean(EslClientService.class);
|
|
54
|
|
- // 获取通道ID
|
|
55
|
|
- String chanId = header.get("Unique-ID");
|
|
56
|
|
- // 获取通道名称
|
|
57
|
|
- String[] chanNames = header.get("Channel-Name").split("@")[0].split("/");
|
|
58
|
|
- Channel chan = EslCommon.getChanByNumber(chanNames[2]);
|
|
59
|
|
- switch (EslEventEnum.valueOf(eventname)) {
|
|
60
|
|
- case CHANNEL_ANSWER:
|
|
61
|
|
- //是否开启语音识别
|
|
62
|
|
- if (SpringHelper.getBean(IConfigService.class).getConfigValue("EnableAsr").equals("1")) {
|
|
63
|
|
- if (chan != null && chan.getSessionSort() >= 2) {
|
|
64
|
|
- startAsr(chanId,eslClientService);
|
|
65
|
|
- if (chan.getSessionSort() == 2) {
|
|
66
|
|
- Channel cl = EslCommon.getFirstChanBySessionId(chan.getSessionId());
|
|
67
|
|
- if (cl != null) startAsr(cl.getChanId(),eslClientService);
|
|
|
46
|
+ break;
|
|
|
47
|
+ }
|
|
|
48
|
+ } else {
|
|
|
49
|
+ EslClientService eslClientService = SpringHelper.getBean(EslClientService.class);
|
|
|
50
|
+ // 获取通道ID
|
|
|
51
|
+ String chanId = header.get("Unique-ID");
|
|
|
52
|
+ // 获取通道名称
|
|
|
53
|
+ String[] chanNames = header.get("Channel-Name").split("@")[0].split("/");
|
|
|
54
|
+ Channel chan = EslCommon.getChanByNumber(chanNames[2]);
|
|
|
55
|
+ switch (EslEventEnum.valueOf(eventname)) {
|
|
|
56
|
+ case CHANNEL_ANSWER:
|
|
|
57
|
+ //是否开启语音识别
|
|
|
58
|
+ if (SpringHelper.getBean(IConfigService.class).getConfigValue("EnableAsr").equals("1")) {
|
|
|
59
|
+ if (chan != null && chan.getSessionSort() >= 2) {
|
|
|
60
|
+ startAsr(chanId, eslClientService);
|
|
|
61
|
+ if (chan.getSessionSort() == 2) {
|
|
|
62
|
+ Channel cl = EslCommon.getFirstChanBySessionId(chan.getSessionId());
|
|
|
63
|
+ if (cl != null) startAsr(cl.getChanId(), eslClientService);
|
|
|
64
|
+ }
|
|
68
|
65
|
}
|
|
69
|
66
|
}
|
|
70
|
|
- }
|
|
71
|
|
- break;
|
|
72
|
|
- case DETECTED_SPEECH:
|
|
73
|
|
- //不是机器人,不是自动外呼
|
|
74
|
|
- if (!(header.containsKey("Caller-Context") && header.get("Caller-Context").equals("robot"))) {
|
|
75
|
|
- if (!(header.containsKey("variable_call_type") && header.get("variable_call_type").equals("3"))) {
|
|
76
|
|
- String speechType = header.get("Speech-Type");
|
|
77
|
|
- if (StringHelper.isNotEmpty(speechType)) {
|
|
78
|
|
- //begin-speaking/detected-speech/closed
|
|
79
|
|
- if (speechType.equals("detected-speech")) {
|
|
80
|
|
- //继续识别
|
|
81
|
|
- eslClientService.appCommand(chanId, "detect_speech", "resume");
|
|
82
|
|
- //识别结果
|
|
83
|
|
- String xmlResult = "";
|
|
84
|
|
- List<String> results = event.getEventBodyLines();
|
|
85
|
|
- if (results.size() > 0) {
|
|
86
|
|
- String xml = String.join("", results);
|
|
87
|
|
- xmlResult = EslCommon.getXmlResult(xml, true);
|
|
88
|
|
- if (StringHelper.isNotEmpty(xmlResult)) {
|
|
89
|
|
- sendAsr(chan, xmlResult,null);
|
|
90
|
|
- }
|
|
|
67
|
+ break;
|
|
|
68
|
+ case DETECTED_SPEECH:
|
|
|
69
|
+ String speechType = header.get("Speech-Type");
|
|
|
70
|
+ if (StringHelper.isNotEmpty(speechType)) {
|
|
|
71
|
+ //begin-speaking/detected-speech/closed
|
|
|
72
|
+ if (speechType.equals("detected-speech")) {
|
|
|
73
|
+ //继续识别
|
|
|
74
|
+ eslClientService.appCommand(chanId, "detect_speech", "resume");
|
|
|
75
|
+ //识别结果
|
|
|
76
|
+ String xmlResult = "";
|
|
|
77
|
+ List<String> results = event.getEventBodyLines();
|
|
|
78
|
+ if (results.size() > 0) {
|
|
|
79
|
+ String xml = String.join("", results);
|
|
|
80
|
+ xmlResult = EslCommon.getXmlResult(xml, true);
|
|
|
81
|
+ if (StringHelper.isNotEmpty(xmlResult)) {
|
|
|
82
|
+ sendAsr(chan, xmlResult, null);
|
|
91
|
83
|
}
|
|
92
|
84
|
}
|
|
93
|
85
|
}
|
|
94
|
86
|
}
|
|
95
|
|
- }
|
|
96
|
|
- break;
|
|
|
87
|
+ break;
|
|
|
88
|
+ }
|
|
97
|
89
|
}
|
|
98
|
90
|
}
|
|
99
|
91
|
}
|