Commit d1a8d11719d66d4c5f1c4dba9e88b62f222535c0
1 parent
ed3b99c2
1 修改语音解析结果逻辑
Showing
9 changed files
with
123 additions
and
79 deletions
gradle/wrapper/gradle-wrapper.jar
0 → 100644
No preview for this file type
gradle/wrapper/gradle-wrapper.properties
0 → 100644
smartAssistant/src/main/java/com/ys/yslibrary/bean/Answer.java
| @@ -4,9 +4,20 @@ package com.ys.yslibrary.bean; | @@ -4,9 +4,20 @@ package com.ys.yslibrary.bean; | ||
| 4 | * 技能处理返回结果,包含展示内容,合成内容和回调 | 4 | * 技能处理返回结果,包含展示内容,合成内容和回调 |
| 5 | */ | 5 | */ |
| 6 | public class Answer { | 6 | public class Answer { |
| 7 | + public static final int TYPE_WEATHER = 1001; | ||
| 8 | + public static final int TYPE_UNKNOWN = 1002; | ||
| 7 | private String mAnswer; | 9 | private String mAnswer; |
| 8 | private String mTTSContent; | 10 | private String mTTSContent; |
| 9 | private Runnable mAnswerCallback; | 11 | private Runnable mAnswerCallback; |
| 12 | + private int answerType; | ||
| 13 | + | ||
| 14 | + public int getAnswerType() { | ||
| 15 | + return answerType; | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + public void setAnswerType(int answerType) { | ||
| 19 | + this.answerType = answerType; | ||
| 20 | + } | ||
| 10 | 21 | ||
| 11 | public Answer(String answer, String ttsContent, Runnable answerCallback) { | 22 | public Answer(String answer, String ttsContent, Runnable answerCallback) { |
| 12 | mAnswer = answer; | 23 | mAnswer = answer; |
| @@ -31,7 +42,9 @@ public class Answer { | @@ -31,7 +42,9 @@ public class Answer { | ||
| 31 | return mAnswer; | 42 | return mAnswer; |
| 32 | } | 43 | } |
| 33 | 44 | ||
| 34 | - public String getTTSContent() { return mTTSContent; } | 45 | + public String getTTSContent() { |
| 46 | + return mTTSContent; | ||
| 47 | + } | ||
| 35 | 48 | ||
| 36 | public Runnable getAnswerCallback() { | 49 | public Runnable getAnswerCallback() { |
| 37 | return mAnswerCallback; | 50 | return mAnswerCallback; |
smartAssistant/src/main/java/com/ys/yslibrary/bean/ChatMessageHandler.java
| 1 | package com.ys.yslibrary.bean; | 1 | package com.ys.yslibrary.bean; |
| 2 | 2 | ||
| 3 | import android.text.TextUtils; | 3 | import android.text.TextUtils; |
| 4 | +import android.util.Log; | ||
| 4 | 5 | ||
| 5 | import com.ys.yslibrary.bean.player.PlayerHandler; | 6 | import com.ys.yslibrary.bean.player.PlayerHandler; |
| 6 | 7 | ||
| @@ -30,6 +31,9 @@ public class ChatMessageHandler { | @@ -30,6 +31,9 @@ public class ChatMessageHandler { | ||
| 30 | static { | 31 | static { |
| 31 | // handlerMap.put("telephone", TelephoneHandler.class); | 32 | // handlerMap.put("telephone", TelephoneHandler.class); |
| 32 | handlerMap.put("weather", WeatherHandler.class); | 33 | handlerMap.put("weather", WeatherHandler.class); |
| 34 | + handlerMap.put(MsgConstant.TYPE_UNKNOWN, UnknownHandler.class); | ||
| 35 | + //历史上的今天 | ||
| 36 | + handlerMap.put("LEIQIAO.historyToday", UnknownHandler.class); | ||
| 33 | // handlerMap.put("cookbook", CookBookHandler.class); | 37 | // handlerMap.put("cookbook", CookBookHandler.class); |
| 34 | // handlerMap.put("stock", StockHandler.class); | 38 | // handlerMap.put("stock", StockHandler.class); |
| 35 | // handlerMap.put("mapU", MapHandler.class); | 39 | // handlerMap.put("mapU", MapHandler.class); |
| @@ -62,15 +66,19 @@ public class ChatMessageHandler { | @@ -62,15 +66,19 @@ public class ChatMessageHandler { | ||
| 62 | private SemanticResult mSemanticResult; | 66 | private SemanticResult mSemanticResult; |
| 63 | private IntentHandler mHandler; | 67 | private IntentHandler mHandler; |
| 64 | 68 | ||
| 69 | + public void reset(){ | ||
| 70 | + mSemanticResult=null; | ||
| 71 | + } | ||
| 65 | 72 | ||
| 66 | - public String getFormatMessage(RawMessage message) { | 73 | + public Answer getFormatMessage(RawMessage message) { |
| 67 | this.mMessage = message; | 74 | this.mMessage = message; |
| 68 | if (mMessage.fromType == RawMessage.FromType.USER) { | 75 | if (mMessage.fromType == RawMessage.FromType.USER) { |
| 69 | //用户消息 | 76 | //用户消息 |
| 70 | if (mMessage.msgType == RawMessage.MsgType.TEXT) { | 77 | if (mMessage.msgType == RawMessage.MsgType.TEXT) { |
| 71 | - return new String(mMessage.msgData); | 78 | +// return new String(mMessage.msgData); |
| 79 | + return new Answer(new String(mMessage.msgData)); | ||
| 72 | } else { | 80 | } else { |
| 73 | - return ""; | 81 | + return null; |
| 74 | } | 82 | } |
| 75 | } else { | 83 | } else { |
| 76 | initHandler(); | 84 | initHandler(); |
| @@ -89,9 +97,9 @@ public class ChatMessageHandler { | @@ -89,9 +97,9 @@ public class ChatMessageHandler { | ||
| 89 | if (!TextUtils.isEmpty(answer.getTTSContent())) { | 97 | if (!TextUtils.isEmpty(answer.getTTSContent())) { |
| 90 | latestTTSAnswer = answer; | 98 | latestTTSAnswer = answer; |
| 91 | } | 99 | } |
| 92 | - return answer.getAnswer(); | 100 | + return answer; |
| 93 | } else { | 101 | } else { |
| 94 | - return "错误"; | 102 | + return null; |
| 95 | } | 103 | } |
| 96 | } | 104 | } |
| 97 | } | 105 | } |
| @@ -108,7 +116,7 @@ public class ChatMessageHandler { | @@ -108,7 +116,7 @@ public class ChatMessageHandler { | ||
| 108 | //根据语义结果的service查找对应的IntentHandler,并实例化 | 116 | //根据语义结果的service查找对应的IntentHandler,并实例化 |
| 109 | Class handlerClass = handlerMap.get(mSemanticResult.service); | 117 | Class handlerClass = handlerMap.get(mSemanticResult.service); |
| 110 | if (handlerClass == null) { | 118 | if (handlerClass == null) { |
| 111 | - handlerClass = PlayerHandler.class; | 119 | + handlerClass = UnknownHandler.class; |
| 112 | } | 120 | } |
| 113 | try { | 121 | try { |
| 114 | Constructor constructor = handlerClass.getConstructor(); | 122 | Constructor constructor = handlerClass.getConstructor(); |
| @@ -134,7 +142,7 @@ public class ChatMessageHandler { | @@ -134,7 +142,7 @@ public class ChatMessageHandler { | ||
| 134 | semanticResult = new JSONObject(new String(mMessage.msgData)); | 142 | semanticResult = new JSONObject(new String(mMessage.msgData)); |
| 135 | mSemanticResult.rc = semanticResult.optInt("rc"); | 143 | mSemanticResult.rc = semanticResult.optInt("rc"); |
| 136 | if (mSemanticResult.rc == 4) { | 144 | if (mSemanticResult.rc == 4) { |
| 137 | -// mSemanticResult.service = Constant.SERVICE_UNKNOWN; | 145 | + mSemanticResult.service = MsgConstant.TYPE_UNKNOWN; |
| 138 | } else if (mSemanticResult.rc == 1) { | 146 | } else if (mSemanticResult.rc == 1) { |
| 139 | mSemanticResult.service = semanticResult.optString("service"); | 147 | mSemanticResult.service = semanticResult.optString("service"); |
| 140 | mSemanticResult.answer = "语义错误"; | 148 | mSemanticResult.answer = "语义错误"; |
| @@ -177,7 +185,7 @@ public class ChatMessageHandler { | @@ -177,7 +185,7 @@ public class ChatMessageHandler { | ||
| 177 | } | 185 | } |
| 178 | } catch (JSONException e) { | 186 | } catch (JSONException e) { |
| 179 | mSemanticResult.rc = 4; | 187 | mSemanticResult.rc = 4; |
| 180 | -// mSemanticResult.service = Constant.SERVICE_UNKNOWN; | 188 | + mSemanticResult.service = MsgConstant.TYPE_UNKNOWN; |
| 181 | } | 189 | } |
| 182 | } | 190 | } |
| 183 | } | 191 | } |
smartAssistant/src/main/java/com/ys/yslibrary/bean/MsgConstant.java
0 → 100644
smartAssistant/src/main/java/com/ys/yslibrary/bean/UnknownHandler.java
0 → 100644
| 1 | +package com.ys.yslibrary.bean; | ||
| 2 | + | ||
| 3 | +import org.json.JSONArray; | ||
| 4 | +import org.json.JSONObject; | ||
| 5 | + | ||
| 6 | +public class UnknownHandler extends IntentHandler { | ||
| 7 | + @Override | ||
| 8 | + public Answer getFormatContent(SemanticResult result) { | ||
| 9 | + Answer answer = new Answer(result.answer); | ||
| 10 | + answer.setAnswerType(Answer.TYPE_UNKNOWN); | ||
| 11 | + return answer; | ||
| 12 | + } | ||
| 13 | +} |
smartAssistant/src/main/java/com/ys/yslibrary/bean/WeatherHandler.java
| @@ -14,25 +14,30 @@ public class WeatherHandler extends IntentHandler { | @@ -14,25 +14,30 @@ public class WeatherHandler extends IntentHandler { | ||
| 14 | 14 | ||
| 15 | @Override | 15 | @Override |
| 16 | public Answer getFormatContent(SemanticResult result) { | 16 | public Answer getFormatContent(SemanticResult result) { |
| 17 | + Answer answer = null; | ||
| 17 | if (notified) { | 18 | if (notified) { |
| 18 | - return new Answer(result.answer); | 19 | + answer = new Answer(result.answer); |
| 20 | + answer.setAnswerType(Answer.TYPE_WEATHER); | ||
| 21 | + return answer; | ||
| 19 | } else { | 22 | } else { |
| 20 | - StringBuilder answer = new StringBuilder(result.answer); | 23 | + StringBuilder builder = new StringBuilder(result.answer); |
| 21 | JSONArray slots = result.semantic.optJSONArray("slots"); | 24 | JSONArray slots = result.semantic.optJSONArray("slots"); |
| 22 | for (int index = 0; index < slots.length(); index++) { | 25 | for (int index = 0; index < slots.length(); index++) { |
| 23 | JSONObject item = slots.optJSONObject(index); | 26 | JSONObject item = slots.optJSONObject(index); |
| 24 | - if (item.optString("name").contains("location")) { | 27 | + if (item != null && item.optString("name") != null && item.optString("name").contains("location")) { |
| 25 | // 问法意图中不包含具体的城市名,提示可使用定位让城市信息更准确 | 28 | // 问法意图中不包含具体的城市名,提示可使用定位让城市信息更准确 |
| 26 | if (item.optString("value").contains("CURRENT_CITY")) { | 29 | if (item.optString("value").contains("CURRENT_CITY")) { |
| 27 | - answer.append(NEWLINE); | ||
| 28 | - answer.append(NEWLINE); | ||
| 29 | - answer.append("<a href=\"use_loc\">使用定位让天气信息更准确</a>"); | 30 | + builder.append(NEWLINE); |
| 31 | + builder.append(NEWLINE); | ||
| 32 | + builder.append("<a href=\"use_loc\">使用定位让天气信息更准确</a>"); | ||
| 30 | notified = true; | 33 | notified = true; |
| 31 | break; | 34 | break; |
| 32 | } | 35 | } |
| 33 | } | 36 | } |
| 34 | } | 37 | } |
| 35 | - return new Answer(answer.toString(), result.answer); | 38 | + answer = new Answer(result.answer, result.answer); |
| 39 | + answer.setAnswerType(Answer.TYPE_WEATHER); | ||
| 40 | + return answer; | ||
| 36 | } | 41 | } |
| 37 | } | 42 | } |
| 38 | 43 |
smartAssistant/src/main/java/com/ys/yslibrary/ui/AssistantActivity.java
| 1 | package com.ys.yslibrary.ui; | 1 | package com.ys.yslibrary.ui; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -import android.app.Dialog; | ||
| 5 | -import android.os.Handler; | ||
| 6 | -import android.os.Message; | ||
| 7 | import android.util.Log; | 4 | import android.util.Log; |
| 8 | import android.view.View; | 5 | import android.view.View; |
| 9 | import android.view.ViewGroup; | 6 | import android.view.ViewGroup; |
| @@ -12,11 +9,9 @@ import android.view.animation.AnimationUtils; | @@ -12,11 +9,9 @@ import android.view.animation.AnimationUtils; | ||
| 12 | import android.view.animation.LayoutAnimationController; | 9 | import android.view.animation.LayoutAnimationController; |
| 13 | import android.widget.HorizontalScrollView; | 10 | import android.widget.HorizontalScrollView; |
| 14 | 11 | ||
| 15 | -import androidx.annotation.NonNull; | ||
| 16 | -import androidx.recyclerview.widget.LinearLayoutManager; | ||
| 17 | -import androidx.recyclerview.widget.RecyclerView; | ||
| 18 | 12 | ||
| 19 | import com.ys.yslibrary.aiui.AIUIWrapper; | 13 | import com.ys.yslibrary.aiui.AIUIWrapper; |
| 14 | +import com.ys.yslibrary.bean.Answer; | ||
| 20 | import com.ys.yslibrary.bean.AssistantContentBean; | 15 | import com.ys.yslibrary.bean.AssistantContentBean; |
| 21 | import com.ys.yslibrary.bean.ChatMessageHandler; | 16 | import com.ys.yslibrary.bean.ChatMessageHandler; |
| 22 | import com.ys.yslibrary.callback.OnVoiceIdentifyResultListener; | 17 | import com.ys.yslibrary.callback.OnVoiceIdentifyResultListener; |
| @@ -27,20 +22,12 @@ import com.ys.yslibrary.ui.adapter.AssistantAdapter; | @@ -27,20 +22,12 @@ import com.ys.yslibrary.ui.adapter.AssistantAdapter; | ||
| 27 | import com.ys.yslibrary.ui.custom.AssistantViewAdapter; | 22 | import com.ys.yslibrary.ui.custom.AssistantViewAdapter; |
| 28 | import com.ys.yslibrary.viewmodel.VoiceViewModel; | 23 | import com.ys.yslibrary.viewmodel.VoiceViewModel; |
| 29 | 24 | ||
| 30 | -import java.util.ArrayList; | ||
| 31 | -import java.util.HashMap; | ||
| 32 | -import java.util.HashSet; | ||
| 33 | -import java.util.Hashtable; | ||
| 34 | -import java.util.List; | ||
| 35 | -import java.util.concurrent.Callable; | ||
| 36 | -import java.util.concurrent.ConcurrentHashMap; | ||
| 37 | 25 | ||
| 38 | public class AssistantActivity extends BaseActivity { | 26 | public class AssistantActivity extends BaseActivity { |
| 39 | private VoiceViewModel mVoiceViewModel; | 27 | private VoiceViewModel mVoiceViewModel; |
| 40 | private ActivityXiaojiaAssistantBinding binding; | 28 | private ActivityXiaojiaAssistantBinding binding; |
| 41 | private ChatMessageHandler messageHandler; | 29 | private ChatMessageHandler messageHandler; |
| 42 | - private AssistantAdapter assistantAdapter; | ||
| 43 | - private List<AssistantContentBean> list; | 30 | + private AssistantViewAdapter viewAdapter; |
| 44 | 31 | ||
| 45 | @Override | 32 | @Override |
| 46 | protected int getBindingLayoutId() { | 33 | protected int getBindingLayoutId() { |
| @@ -55,19 +42,17 @@ public class AssistantActivity extends BaseActivity { | @@ -55,19 +42,17 @@ public class AssistantActivity extends BaseActivity { | ||
| 55 | @Override | 42 | @Override |
| 56 | protected void init() { | 43 | protected void init() { |
| 57 | this.binding = (ActivityXiaojiaAssistantBinding) getBaseBinding(); | 44 | this.binding = (ActivityXiaojiaAssistantBinding) getBaseBinding(); |
| 58 | - this.list = new ArrayList<>(); | ||
| 59 | - assistantAdapter = new AssistantAdapter(this, list); | ||
| 60 | 45 | ||
| 61 | // binding.rv.setLayoutManager(new LinearLayoutManager(this)); | 46 | // binding.rv.setLayoutManager(new LinearLayoutManager(this)); |
| 62 | // binding.rv.setAdapter(assistantAdapter); | 47 | // binding.rv.setAdapter(assistantAdapter); |
| 63 | 48 | ||
| 64 | getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); | 49 | getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); |
| 65 | messageHandler = new ChatMessageHandler(); | 50 | messageHandler = new ChatMessageHandler(); |
| 66 | -// AIUIWrapper.getInstance().startRecordAudio(); | 51 | + AIUIWrapper.getInstance().startRecordAudio(); |
| 67 | AssistantContentBean assistantContentBean = new AssistantContentBean(AssistantContentBean.TYPE_WEATHER); | 52 | AssistantContentBean assistantContentBean = new AssistantContentBean(AssistantContentBean.TYPE_WEATHER); |
| 68 | - assistantContentBean.setWeather("天气好"); | ||
| 69 | - AssistantViewAdapter viewAdapter = new AssistantViewAdapter(this, assistantContentBean); | 53 | + viewAdapter = new AssistantViewAdapter(this, assistantContentBean); |
| 70 | 54 | ||
| 55 | + binding.assistantView.setVisibility(View.GONE); | ||
| 71 | binding.assistantView.setLayoutAnimation(AnimationUtils.loadLayoutAnimation(this, R.anim.layout_animation_fall_down)); | 56 | binding.assistantView.setLayoutAnimation(AnimationUtils.loadLayoutAnimation(this, R.anim.layout_animation_fall_down)); |
| 72 | binding.assistantView.setAdapter(viewAdapter); | 57 | binding.assistantView.setAdapter(viewAdapter); |
| 73 | binding.assistantView.setOnClickBlankBgListener(new View.OnClickListener() { | 58 | binding.assistantView.setOnClickBlankBgListener(new View.OnClickListener() { |
| @@ -76,15 +61,15 @@ public class AssistantActivity extends BaseActivity { | @@ -76,15 +61,15 @@ public class AssistantActivity extends BaseActivity { | ||
| 76 | finish(); | 61 | finish(); |
| 77 | } | 62 | } |
| 78 | }); | 63 | }); |
| 79 | - new Handler().postDelayed(new Runnable() { | ||
| 80 | - @Override | ||
| 81 | - public void run() { | ||
| 82 | - AssistantContentBean assistantContentBean = new AssistantContentBean(AssistantContentBean.TYPE_DIALOGUE); | ||
| 83 | - assistantContentBean.setDialogue("修奥对话"); | ||
| 84 | - viewAdapter.setChangeData(assistantContentBean); | ||
| 85 | - viewAdapter.notifyAllChange(); | ||
| 86 | - } | ||
| 87 | - }, 3000); | 64 | +// new Handler().postDelayed(new Runnable() { |
| 65 | +// @Override | ||
| 66 | +// public void run() { | ||
| 67 | +// AssistantContentBean assistantContentBean = new AssistantContentBean(AssistantContentBean.TYPE_DIALOGUE); | ||
| 68 | +// assistantContentBean.setDialogue("修奥对话"); | ||
| 69 | +// viewAdapter.setChangeData(assistantContentBean); | ||
| 70 | +// viewAdapter.notifyAllChange(); | ||
| 71 | +// } | ||
| 72 | +// }, 3000); | ||
| 88 | 73 | ||
| 89 | // list.add(assistantContentBean); | 74 | // list.add(assistantContentBean); |
| 90 | //// assistantAdapter.notifyItemInserted(0); | 75 | //// assistantAdapter.notifyItemInserted(0); |
| @@ -98,40 +83,47 @@ public class AssistantActivity extends BaseActivity { | @@ -98,40 +83,47 @@ public class AssistantActivity extends BaseActivity { | ||
| 98 | // binding.rv.scheduleLayoutAnimation(); | 83 | // binding.rv.scheduleLayoutAnimation(); |
| 99 | // } | 84 | // } |
| 100 | // }, 3000); | 85 | // }, 3000); |
| 101 | -// AIUIWrapper.getInstance().setVoiceIdentifyResultListener(new OnVoiceIdentifyResultListener() { | ||
| 102 | -// @Override | ||
| 103 | -// public void onResult(boolean isIATResult, RawMessage rawMessage) { | ||
| 104 | -// if (rawMessage != null) { | ||
| 105 | -// if (rawMessage.isFromUser()) { | ||
| 106 | -// binding.rv.setVisibility(View.INVISIBLE); | ||
| 107 | -// binding.tvMsg.setText(isIATResult ? rawMessage.cacheContent : String.valueOf(rawMessage.msgData)); | ||
| 108 | -// if (!isIATResult) { | ||
| 109 | -// Log.e("TAG", "onResult: " + new String(rawMessage.msgData)); | ||
| 110 | -// } | ||
| 111 | -// //滑动到最后一位 | ||
| 112 | -// binding.hscroll.fullScroll(HorizontalScrollView.FOCUS_RIGHT); | ||
| 113 | -// } else { | ||
| 114 | -// binding.rv.setVisibility(View.VISIBLE); | ||
| 115 | -// //非用户说的 | ||
| 116 | -// String result = messageHandler.getFormatMessage(rawMessage); | ||
| 117 | -// list.clear(); | ||
| 118 | -// Animation animation = AnimationUtils.loadAnimation(AssistantActivity.this, R.anim.anim_bottom); | ||
| 119 | -// //得到一个LayoutAnimationController对象; | ||
| 120 | -// LayoutAnimationController lac = new LayoutAnimationController(animation); | ||
| 121 | -// binding.rv.setLayoutAnimation(lac); | ||
| 122 | -// | ||
| 123 | -// AssistantContentBean assistantContentBean = new AssistantContentBean(AssistantContentBean.TYPE_WEATHER); | ||
| 124 | -// assistantContentBean.setWeather(result); | ||
| 125 | -// list.add(assistantContentBean); | ||
| 126 | -// assistantAdapter.notifyDataSetChanged(); | ||
| 127 | -// binding.rv.scheduleLayoutAnimation(); | ||
| 128 | -// } | ||
| 129 | -// | ||
| 130 | -// } else { | ||
| 131 | -// binding.tvMsg.setText("什么也没说"); | ||
| 132 | -// } | ||
| 133 | -// } | ||
| 134 | -// }); | 86 | + binding.assistantView.setVisibility(View.INVISIBLE); |
| 87 | + AIUIWrapper.getInstance().setVoiceIdentifyResultListener(new OnVoiceIdentifyResultListener() { | ||
| 88 | + @Override | ||
| 89 | + public void onResult(boolean isIATResult, RawMessage rawMessage) { | ||
| 90 | + if (rawMessage != null) { | ||
| 91 | + if (rawMessage.isFromUser()) { | ||
| 92 | + | ||
| 93 | + binding.tvMsg.setText(isIATResult ? rawMessage.cacheContent : String.valueOf(rawMessage.msgData)); | ||
| 94 | + if (!isIATResult) { | ||
| 95 | + Log.e("TAG", "onResult: " + new String(rawMessage.msgData)); | ||
| 96 | + } | ||
| 97 | + //滑动到最后一位 | ||
| 98 | + binding.hscroll.fullScroll(HorizontalScrollView.FOCUS_RIGHT); | ||
| 99 | + } else { | ||
| 100 | + binding.assistantView.setVisibility(View.VISIBLE); | ||
| 101 | + //非用户说的 | ||
| 102 | + Answer result = messageHandler.getFormatMessage(rawMessage); | ||
| 103 | + AssistantContentBean assistantContentBean = new AssistantContentBean(AssistantContentBean.TYPE_WEATHER); | ||
| 104 | + assistantContentBean.setWeather(result.getAnswer()); | ||
| 105 | + viewAdapter.setChangeData(assistantContentBean); | ||
| 106 | + viewAdapter.notifyAllChange(); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + } else { | ||
| 110 | + binding.tvMsg.setText("什么也没说"); | ||
| 111 | + } | ||
| 112 | + } | ||
| 113 | + }); | ||
| 114 | + | ||
| 115 | + binding.tvMsg.setOnClickListener(new View.OnClickListener() { | ||
| 116 | + @Override | ||
| 117 | + public void onClick(View v) { | ||
| 118 | + reSpeak(); | ||
| 119 | + } | ||
| 120 | + }); | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + private void reSpeak() { | ||
| 124 | + messageHandler.reset(); | ||
| 125 | + AIUIWrapper.getInstance().startRecordAudio(); | ||
| 126 | + binding.tvMsg.setText("倾听中..."); | ||
| 135 | } | 127 | } |
| 136 | 128 | ||
| 137 | @Override | 129 | @Override |
smartAssistant/src/main/res/layout/activity_xiaojia_assistant.xml
| @@ -11,6 +11,7 @@ | @@ -11,6 +11,7 @@ | ||
| 11 | android:layout_height="match_parent" | 11 | android:layout_height="match_parent" |
| 12 | android:background="@android:color/transparent"> | 12 | android:background="@android:color/transparent"> |
| 13 | 13 | ||
| 14 | + | ||
| 14 | <com.ys.yslibrary.ui.custom.AssistantView | 15 | <com.ys.yslibrary.ui.custom.AssistantView |
| 15 | android:id="@+id/assistant_view" | 16 | android:id="@+id/assistant_view" |
| 16 | android:layout_width="match_parent" | 17 | android:layout_width="match_parent" |
| @@ -18,6 +19,7 @@ | @@ -18,6 +19,7 @@ | ||
| 18 | app:layout_constraintBottom_toTopOf="@id/iv_icon" | 19 | app:layout_constraintBottom_toTopOf="@id/iv_icon" |
| 19 | app:layout_constraintTop_toTopOf="parent" /> | 20 | app:layout_constraintTop_toTopOf="parent" /> |
| 20 | 21 | ||
| 22 | + | ||
| 21 | <ImageView | 23 | <ImageView |
| 22 | android:id="@+id/iv_icon" | 24 | android:id="@+id/iv_icon" |
| 23 | android:layout_width="20dp" | 25 | android:layout_width="20dp" |