|
|
@@ -259,6 +259,9 @@ public class RobotChat extends RobotBase {
|
|
|
if(EventNames.PLAYBACK_START.equalsIgnoreCase(detail)) {
|
|
|
chatRobot.setTtsChannelState(TtsChannelState.OPENED);
|
|
|
chatRobot.flushTtsRequestQueue();
|
|
|
+ if (playbackStartTime <= 0) {
|
|
|
+ playbackStartTime = System.currentTimeMillis();
|
|
|
+ }
|
|
|
long timeSpent = System.currentTimeMillis() - playbackStartTime;
|
|
|
logger.info("{} PLAYBACK_START event, time cost = {} ms. ", getTraceId(), timeSpent);
|
|
|
}
|
|
|
@@ -423,11 +426,17 @@ public class RobotChat extends RobotBase {
|
|
|
ttsChannelClosed = true;
|
|
|
recvPlayBackEndEvent = true;
|
|
|
playbackEndTime = System.currentTimeMillis();
|
|
|
+ if (playbackStartTime > 0) {
|
|
|
+ roundTtsCostMs = playbackEndTime - playbackStartTime;
|
|
|
+ }
|
|
|
releasePlayBackFinishedSignal();
|
|
|
}
|
|
|
if("Speech-Open".equalsIgnoreCase(event)){
|
|
|
chatRobot.setTtsChannelState(TtsChannelState.OPENED);
|
|
|
chatRobot.flushTtsRequestQueue();
|
|
|
+ if (playbackStartTime <= 0) {
|
|
|
+ playbackStartTime = System.currentTimeMillis();
|
|
|
+ }
|
|
|
long timeSpent = System.currentTimeMillis() - playbackStartTime;
|
|
|
logger.info("{} Speech-Open event, time cost = {} ms. ", getTraceId(), timeSpent);
|
|
|
}
|
|
|
@@ -559,6 +568,10 @@ public class RobotChat extends RobotBase {
|
|
|
|
|
|
if (!StringUtil.isNullOrEmpty(asrResponse)) {
|
|
|
asrResultEx.add(asrResponse);
|
|
|
+ roundAsrText = asrResponse;
|
|
|
+ if (asrWaitStartTime > 0) {
|
|
|
+ roundAsrCostMs = System.currentTimeMillis() - asrWaitStartTime;
|
|
|
+ }
|
|
|
// #region debug-point xfyun-asr-no-response-asr-cache
|
|
|
logger.info("{} dbg_asr_event cached vad result, queueSize={}, response={}",
|
|
|
getTraceId(),
|
|
|
@@ -573,6 +586,11 @@ public class RobotChat extends RobotBase {
|
|
|
interruptRobotSpeech();
|
|
|
releasePlayBackFinishedSignal();
|
|
|
ThreadUtil.sleep(100);
|
|
|
+ } else if(chatRobot.getAccount().interruptFlag == 2 && !recvPlayBackEndEvent) {
|
|
|
+ logger.info("{} interruptFlag=2 barge-in detected by vad event, interrupt current robot speech.", getTraceId());
|
|
|
+ interruptRobotSpeech();
|
|
|
+ releasePlayBackFinishedSignal();
|
|
|
+ ThreadUtil.sleep(100);
|
|
|
} else if(chatRobot.getAccount().interruptFlag == 1 && !recvPlayBackEndEvent) {
|
|
|
if (checkSpeechInterrupt(asrResponse)) {
|
|
|
interruptRobotSpeech();
|
|
|
@@ -685,6 +703,10 @@ public class RobotChat extends RobotBase {
|
|
|
try {
|
|
|
String tmpResult = URLDecoder.decode(speechResult,"utf-8").replace(" ","");
|
|
|
asrResultEx.add(tmpResult);
|
|
|
+ roundAsrText = tmpResult;
|
|
|
+ if (asrWaitStartTime > 0) {
|
|
|
+ roundAsrCostMs = System.currentTimeMillis() - asrWaitStartTime;
|
|
|
+ }
|
|
|
logger.info("{} kaldi asr response: {}",getTraceId(), tmpResult);
|
|
|
} catch (Throwable e) {
|
|
|
logger.error("{} URLDecoder.decode Error: {}", getTraceId(), speechResult);
|
|
|
@@ -753,6 +775,35 @@ public class RobotChat extends RobotBase {
|
|
|
if (checkCallSession()) {
|
|
|
return;
|
|
|
}
|
|
|
+ // print round timing summary for previous round and save to database
|
|
|
+ if (roundAsrCostMs > 0 || roundLlmCostMs > 0 || roundTtsCostMs > 0) {
|
|
|
+ long roundTotalMs = roundAsrCostMs + roundLlmCostMs + roundTtsCostMs;
|
|
|
+ logger.info("{} round timing summary: ASR={}ms, LLM={}ms, TTS={}ms, total={}ms",
|
|
|
+ getTraceId(), roundAsrCostMs, roundLlmCostMs, roundTtsCostMs, roundTotalMs);
|
|
|
+ try {
|
|
|
+ com.telerobot.fs.entity.po.CallRound callRound = new com.telerobot.fs.entity.po.CallRound();
|
|
|
+ long roundNo = talkRound.sum();
|
|
|
+ callRound.setId(uuid + "-" + roundNo);
|
|
|
+ callRound.setUuid(uuid);
|
|
|
+ callRound.setRoundNo((int) roundNo);
|
|
|
+ callRound.setAsrText(roundAsrText != null ? roundAsrText : "");
|
|
|
+ callRound.setLlmText(roundLlmText != null ? roundLlmText : "");
|
|
|
+ callRound.setAsrCostMs(roundAsrCostMs);
|
|
|
+ callRound.setLlmCostMs(roundLlmCostMs);
|
|
|
+ callRound.setTtsCostMs(roundTtsCostMs);
|
|
|
+ callRound.setCreateTime(System.currentTimeMillis());
|
|
|
+ com.telerobot.fs.service.CallRoundService callRoundService =
|
|
|
+ com.telerobot.fs.config.AppContextProvider.getBean(com.telerobot.fs.service.CallRoundService.class);
|
|
|
+ callRoundService.insertCallRound(callRound);
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.warn("{} failed to save call round timing: {}", getTraceId(), e.getMessage());
|
|
|
+ }
|
|
|
+ roundAsrCostMs = 0;
|
|
|
+ roundLlmCostMs = 0;
|
|
|
+ roundTtsCostMs = 0;
|
|
|
+ roundAsrText = null;
|
|
|
+ roundLlmText = null;
|
|
|
+ }
|
|
|
// #region debug-point xfyun-asr-no-response-interact-enter
|
|
|
logger.info("{} dbg_interact enter, asrQueueSize={}, recvPlayBackEndEvent={}, ttsChannelClosed={}, inSpeaking={}, noVoiceCounter={}, transferToAgent={}, keepAiDuringTransferWait={}, manualAnsweredTime={}, isReleased={}",
|
|
|
getTraceId(),
|
|
|
@@ -794,6 +845,7 @@ public class RobotChat extends RobotBase {
|
|
|
|
|
|
// 识别开始时间
|
|
|
Long startTime = System.currentTimeMillis();
|
|
|
+ playbackStartTime = 0; // will be set on Speech-Open or first TTS event
|
|
|
LlmAiphoneRes aiphoneRes;
|
|
|
|
|
|
try {
|
|
|
@@ -855,6 +907,8 @@ public class RobotChat extends RobotBase {
|
|
|
|
|
|
talkRound.increment();
|
|
|
Long spentCost = System.currentTimeMillis() - startTime;
|
|
|
+ roundLlmCostMs = spentCost;
|
|
|
+ roundLlmText = aiphoneRes.getBody();
|
|
|
logger.info("{} talkWithLargeModel spent time: {} ms, aiphoneRes = {}",
|
|
|
getTraceId(), spentCost, JSON.toJSONString(aiphoneRes)
|
|
|
);
|
|
|
@@ -1176,6 +1230,7 @@ public class RobotChat extends RobotBase {
|
|
|
}
|
|
|
|
|
|
long startWaitTimeMills = System.currentTimeMillis();
|
|
|
+ asrWaitStartTime = startWaitTimeMills;
|
|
|
logger.info("{} wait for customer speaking ...", getTraceId());
|
|
|
|
|
|
Integer maxWaitTimeCustomerSpeaking = Integer.parseInt(SystemConfig.getValue("max-wait-time-customer-speaking", "7000")) ;
|