* 對話是靈聚APP最基本的交互。用戶輸入文本發送給robot(靈聚智能引擎),robot則針對該輸入進行快速分析并作出應答,從而完成一次對話交互。具體過程如下:
### 1. 用戶輸入
* 鍵盤輸入。觸發MainActivity的sendMsg2Robot( )將輸入框中的文本發送到APP的調度中心AssistantService,讓其發送給robot。
```
@OnClick(R.id.index_text_send_bt)
void sendMsg2Robot() {...}
```
* 語音輸入。在VoiceMediator的語音識別結果回調onRecognizeResult(String)中獲得輸入文本,通過VoiceInputListener的onInput(String)發送給AssistantService,讓其發送給robot。
~~~
public void onRecoginzeResult(String result) {
...
if (!TextUtils.isEmpty(result) && !"。".equals(result)) {
...
//將識別結果發送給機器人
if (inputListener != null) {
inputListener.onInput(result);
...
}
} else {
onRecognizeError(ErrorCode.MSP_ERROR_NO_DATA, "");
}
}
~~~
### 2. Robot應答
robot對輸入文本進行分析處理完畢后,會回調AssistantService.RobotResponseCallBack的
~~~
public void onResult(IChatResult r) {
...
processors.get(?).handle(r.cmd(), text, type);
...
}
~~~
該方法會將robot返回的指令返回至方法中,開發者需在該方法中對應答指令進行分類,然后調用對應類型的Processor的指令處理方法
~~~
/**
* 處理Robot返回的指令
*
* @param cmd 輸出指令
* @param text 輸出文本
* @param inputType 輸入類型
*/
public void handle(Command cmd, String text, int inputType);
~~~
對指令再進行細分并解析、執行,同時將解析到的回復信息通過EventBus post到前端Activity展示(功能指令處理詳見第4章)。