001package com.aispeech.dui.dds.agent.wakeup.word;
002
003import android.text.TextUtils;
004
005import com.aispeech.dui.BusClient;
006import com.aispeech.dui.dds.DDS;
007import com.aispeech.dui.dds.agent.wakeup.WakeupCallback;
008import com.aispeech.dui.dds.exceptions.DDSNotInitCompleteException;
009import com.aispeech.dui.manager.AIJavaException;
010import com.aispeech.dui.manager.AILog;
011import com.aispeech.libcomm.business.LocalKeys;
012import com.aispeech.libcomm.business.LocalKeysUtil;
013import com.aispeech.libcomm.business.topic.WakeupTopicUtil;
014
015import org.json.JSONArray;
016import org.json.JSONException;
017import org.json.JSONObject;
018
019import java.util.Iterator;
020import java.util.List;
021
022public class WordProxy {
023    private static final String TAG = "WakeupWordProxy";
024
025    private WakeupCallback mWakeupCallback;
026
027    /**
028     * 定制欢迎语
029     *
030     * @param wakeupResult 唤醒状态
031     * @return 欢迎语
032     */
033    public BusClient.RPCResult getGreetingRecResult(JSONObject wakeupResult) {
034        if (mWakeupCallback != null) {
035            AILog.userO(TAG, "getGreetingRecResult result =", wakeupResult.toString());
036            JSONObject greetingObj = mWakeupCallback.onWakeup(wakeupResult);
037            AILog.userI(TAG, "getGreetingRecResult input =", (greetingObj != null ? greetingObj.toString() : "null"));
038            if (greetingObj != null) {
039                return new BusClient.RPCResult(greetingObj.toString());
040            }
041        }
042        return null;
043    }
044
045    /**
046     * 设置自定义欢迎语的回调
047     *
048     * @param wakeupCallback 自定义唤醒的回调
049     */
050    public void setWakeupCallback(WakeupCallback wakeupCallback) {
051        this.mWakeupCallback = wakeupCallback;
052    }
053
054    /**
055     * 更新唤醒词,合并请求
056     *
057     * @param intents 合并请求意图
058     */
059    public void updateWakeupWords(List<WakeupWordIntent> intents) throws DDSNotInitCompleteException {
060        String tag = "updateWakeupWords";
061        checkInitComplete();
062        JSONArray jsonArray = WordListUtil.getIntentJsonObject(intents);
063        AILog.userI(TAG, "updateWakeupWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
064        if (jsonArray.length() > 0) {
065            BusClient bc = DDS.getInstance().getAgent().getBusClient();
066            WakeupTopicUtil.publishStickyUpdateWakeupword(bc, jsonArray);
067        }
068    }
069
070    /**
071     * 添加主唤醒词的接口
072     */
073    public void addMainWakeupWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
074        String tag = "addMainWakeupWords";
075        checkInitComplete();
076        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, WakeupType.ADD_MAIN);
077        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
078        AILog.userI(TAG, "addMainWakeupWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
079        if (jsonArray.length() > 0) {
080            BusClient bc = DDS.getInstance().getAgent().getBusClient();
081            WakeupTopicUtil.publishStickyUpdateMainword(bc, jsonArray, "add");
082        }
083    }
084
085    /**
086     * 删除主唤醒词的接口
087     */
088    public void removeMainWakeupWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
089        String tag = "removeMainWakeupWords";
090        checkInitComplete();
091        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, WakeupType.REMOVE_MAIN);
092        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
093        AILog.userI(TAG, "removeMainWakeupWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
094        if (jsonArray.length() > 0) {
095            BusClient bc = DDS.getInstance().getAgent().getBusClient();
096            WakeupTopicUtil.publishStickyUpdateMainword(bc, jsonArray, "remove");
097        }
098    }
099
100    /**
101     * 更新主唤醒词的接口
102     */
103    public void updateMainWakeupWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
104        String tag = "updateMainWakeupWords";
105        checkInitComplete();
106        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, WakeupType.UPDATE_MAIN);
107        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
108        AILog.userI(TAG, "updateMainWakeupWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
109        if (jsonArray.length() > 0) {
110            BusClient bc = DDS.getInstance().getAgent().getBusClient();
111            WakeupTopicUtil.publishStickyUpdateMainword(bc, jsonArray, "update");
112        }
113    }
114
115    /**
116     * 清除主唤醒词的接口
117     */
118    public void clearMainWakeupWords() throws DDSNotInitCompleteException {
119        checkInitComplete();
120        BusClient bc = DDS.getInstance().getAgent().getBusClient();
121        WakeupTopicUtil.publishStickyUpdateMainword(bc, new JSONArray(), "clear");
122    }
123
124
125    /**
126     * 添加QuickStart词的接口
127     */
128    public void addQuickStartWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
129        String tag = "addQuickStartWords";
130        checkInitComplete();
131        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, WakeupType.ADD_QUICKSTART);
132        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
133        AILog.userI(TAG, "addQuickStartWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
134        if (jsonArray.length() > 0) {
135            BusClient bc = DDS.getInstance().getAgent().getBusClient();
136            WakeupTopicUtil.publishStickyUpdateQuickstart(bc, jsonArray, "add");
137        }
138    }
139
140    /**
141     * 删除QuickStart词的接口
142     */
143    public void removeQuickStartWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
144        String tag = "removeQuickStartWords";
145        checkInitComplete();
146        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, WakeupType.REMOVE_QUICKSTART);
147        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
148        AILog.userI(TAG, "removeQuickStartWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
149        if (jsonArray.length() > 0) {
150            BusClient bc = DDS.getInstance().getAgent().getBusClient();
151            WakeupTopicUtil.publishStickyUpdateQuickstart(bc, jsonArray, "remove");
152        }
153    }
154
155    /**
156     * 更新QuickStart词的接口
157     */
158    public void updateQuickStartWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
159        String tag = "updateQuickStartWords";
160        checkInitComplete();
161        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, WakeupType.UPDATE_QUICKSTART);
162        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
163        AILog.userI(TAG, "updateQuickStartWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
164        if (jsonArray.length() > 0) {
165            BusClient bc = DDS.getInstance().getAgent().getBusClient();
166            WakeupTopicUtil.publishStickyUpdateQuickstart(bc, jsonArray, "update");
167        }
168    }
169
170    /**
171     * 清除QuickStart词的接口
172     */
173    public void clearQuickStartWords() throws DDSNotInitCompleteException {
174        checkInitComplete();
175        BusClient bc = DDS.getInstance().getAgent().getBusClient();
176        WakeupTopicUtil.publishStickyUpdateQuickstart(bc, new JSONArray(), "clear");
177    }
178
179    /**
180     * 更新副唤醒词的接口
181     */
182    public void updateMinorWakeupWord(WakeupWord wakeupWord) throws DDSNotInitCompleteException {
183        String tag = "updateMinorWakeupWord";
184        checkInitComplete();
185        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, WakeupType.UPDATE_MINOR);
186        JSONObject jsonObject = createEngine.getJsonObject(wakeupWord);
187        AILog.userI(TAG, "updateMinorWakeupWord input =", (jsonObject != null ? jsonObject.toString() : "null"));
188        if (jsonObject != null) {
189            BusClient bc = DDS.getInstance().getAgent().getBusClient();
190            WakeupTopicUtil.publishStickyRenameMinorWord(bc, jsonObject);
191        }
192    }
193
194    /**
195     * 更新命令唤醒词的接口
196     */
197    public void updateCommandWakeupWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
198        String tag = "updateCommandWakeupWords";
199        checkInitComplete();
200        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, getRealWakeupType(WakeupType.UPDATE_COMMAND, wakeupWordList));
201        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
202        AILog.userI(TAG, "updateCommandWakeupWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
203        if (jsonArray.length() > 0) {
204            BusClient bc = DDS.getInstance().getAgent().getBusClient();
205            WakeupTopicUtil.publishStickyUpdateCmdword(bc, isWakeupIncrementTopic(wakeupWordList), jsonArray, "update");
206        }
207    }
208
209    /**
210     * 添加命令唤醒词,且不会覆盖之前的命令唤醒词
211     */
212    public void addCommandWakeupWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
213        String tag = "addCommandWakeupWords";
214        checkInitComplete();
215        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, getRealWakeupType(WakeupType.ADD_COMMAND, wakeupWordList));
216        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
217        AILog.userI(TAG, "addCommandWakeupWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
218        if (jsonArray.length() > 0) {
219            BusClient bc = DDS.getInstance().getAgent().getBusClient();
220            WakeupTopicUtil.publishStickyUpdateCmdword(bc, isWakeupIncrementTopic(wakeupWordList), jsonArray, "add");
221        }
222    }
223
224    /**
225     * 移除指定的命令唤醒词
226     */
227    public void removeCommandWakeupWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
228        String tag = "removeCommandWakeupWords";
229        checkInitComplete();
230        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, getRealRemoveType(WakeupType.REMOVE_COMMAND, wakeupWordList));
231        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
232        AILog.userI(TAG, "removeCommandWakeupWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
233        if (jsonArray.length() > 0) {
234            BusClient bc = DDS.getInstance().getAgent().getBusClient();
235            WakeupTopicUtil.publishStickyUpdateCmdword(bc, isWakeupIncrementTopic(wakeupWordList), jsonArray, "remove");
236        }
237    }
238
239    /**
240     * 更新打断唤醒词的接口,这类唤醒词能打断正在播报的语音并且将唤醒词送入识别
241     */
242    public void updateShortcutWakeupWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
243        String tag = "updateShortcutWakeupWords";
244        checkInitComplete();
245        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, getRealWakeupType(WakeupType.UPDATE_SHORTCUT, wakeupWordList));
246        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
247        AILog.userI(TAG, "updateShortcutWakeupWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
248        if (jsonArray.length() > 0) {
249            BusClient bc = DDS.getInstance().getAgent().getBusClient();
250            WakeupTopicUtil.publishStickyUpdateFixword(bc, isWakeupIncrementTopic(wakeupWordList), jsonArray, "update");
251        }
252    }
253
254    /**
255     * 添加新的打断唤醒词,且不会覆盖之前的唤醒词
256     */
257    public void addShortcutWakeupWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
258        String tag = "addShortcutWakeupWords";
259        checkInitComplete();
260        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, getRealWakeupType(WakeupType.ADD_SHORTCUT, wakeupWordList));
261        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
262        AILog.userI(TAG, "addShortcutWakeupWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
263        if (jsonArray.length() > 0) {
264            BusClient bc = DDS.getInstance().getAgent().getBusClient();
265            WakeupTopicUtil.publishStickyUpdateFixword(bc, isWakeupIncrementTopic(wakeupWordList), jsonArray, "add");
266        }
267    }
268
269    /**
270     * 移除指定的打断唤醒词
271     */
272    public void removeShortcutWakeupWords(List<WakeupWord> wakeupWordList) throws DDSNotInitCompleteException {
273        String tag = "removeShortcutWakeupWords";
274        checkInitComplete();
275        ICreateEngine createEngine = CreateEngineFactory.getCreateEngine(tag, getRealRemoveType(WakeupType.REMOVE_SHORTCUT, wakeupWordList));
276        JSONArray jsonArray = createEngine.getJsonArray(wakeupWordList);
277        AILog.userI(TAG, "removeShortcutWakeupWords input =", (jsonArray != null ? jsonArray.toString() : "null"));
278        if (jsonArray.length() > 0) {
279            BusClient bc = DDS.getInstance().getAgent().getBusClient();
280            WakeupTopicUtil.publishStickyUpdateFixword(bc, isWakeupIncrementTopic(wakeupWordList), jsonArray, "remove");
281        }
282    }
283
284    /**
285     * 获取当前的唤醒词
286     */
287    public String[] getWakeupWords() throws DDSNotInitCompleteException {
288        checkInitComplete();
289        String[] wakeupList = null;
290        String wakeupWords = getFromKeys(LocalKeys.Wakeup.LOCAL_KEY_WAKEUP_WORD);
291        if (!TextUtils.isEmpty(wakeupWords)) {
292            if (wakeupWords.contains("|")) {
293                wakeupList = wakeupWords.split("\\|");
294            } else {
295                wakeupList = new String[]{wakeupWords};
296            }
297        }
298        return wakeupList;
299    }
300
301    private String getFromKeys(String key, String defaultValue) throws DDSNotInitCompleteException {
302        String value = getFromKeys(key);
303        return (value != null && "".equals(value)) ? value : defaultValue;
304    }
305
306    /**
307     * Get the string value from local_keys using the key.
308     *
309     * @param key
310     * @return null for no keys stored.
311     */
312    private String getFromKeys(String key) throws DDSNotInitCompleteException {
313        checkInitPartComplete();
314        return LocalKeysUtil.getInstance().getString(key);
315    }
316
317    /**
318     * 获取当前的副唤醒词
319     */
320    public String getMinorWakeupWord() throws DDSNotInitCompleteException {
321        checkInitComplete();
322        String ret = null;
323        String minorWakeupWordJson = getFromKeys(LocalKeys.Wakeup.LOCAL_KEY_MINOR);
324        if (!TextUtils.isEmpty(minorWakeupWordJson)) {
325            try {
326                JSONObject minorWakeupWordJsonObj = new JSONObject(minorWakeupWordJson);
327                Iterator<String> iterator = minorWakeupWordJsonObj.keys();
328                if (iterator.hasNext()) {
329                    String key = iterator.next();
330                    JSONObject minorJson = minorWakeupWordJsonObj.optJSONObject(key);
331                    if (minorJson != null)
332                        ret = minorJson.optString("name");
333                }
334
335            } catch (JSONException e) {
336                AIJavaException.printException(e);
337            }
338        }
339        return TextUtils.isEmpty(ret) ? null : ret;
340    }
341
342    /**
343     * 清空命令唤醒词的接口
344     */
345    public void clearCommandWakeupWord() throws DDSNotInitCompleteException {
346        checkInitComplete();
347        BusClient bc = DDS.getInstance().getAgent().getBusClient();
348        WakeupTopicUtil.publishStickyUpdateCmdword(bc, false, new JSONArray(), "clear");
349    }
350
351    /**
352     * 清空打断唤醒词的接口
353     */
354    public void clearShortCutWakeupWord() throws DDSNotInitCompleteException {
355        checkInitComplete();
356        BusClient bc = DDS.getInstance().getAgent().getBusClient();
357        WakeupTopicUtil.publishStickyUpdateFixword(bc, false, new JSONArray(), "clear");
358    }
359
360    /**
361     * 清空命令唤醒词的接口
362     */
363    public void clearIncrementCommandWakeupWord() throws DDSNotInitCompleteException {
364        checkInitComplete();
365        BusClient bc = DDS.getInstance().getAgent().getBusClient();
366        WakeupTopicUtil.publishStickyClearIncrementWakeup(bc, "command");
367    }
368
369    /**
370     * 清空 本地增量识别 打断唤醒词的接口
371     */
372    public void clearIncrementShortCutWakeupWord() throws DDSNotInitCompleteException {
373        checkInitComplete();
374        BusClient bc = DDS.getInstance().getAgent().getBusClient();
375        WakeupTopicUtil.publishStickyClearIncrementWakeup(bc, "interrupt");
376    }
377
378
379    /**
380     * 清空 本地增量识别 命令唤醒词的接口
381     */
382    public void clearIncrementWakeupWord() throws DDSNotInitCompleteException {
383        checkInitComplete();
384        BusClient bc = DDS.getInstance().getAgent().getBusClient();
385        WakeupTopicUtil.publishStickyClearIncrementWakeup(bc, null);
386    }
387
388
389    /**
390     * 开启本地热词分级功能
391     */
392    public void enableIncrementWakeupPriority(String priority) throws DDSNotInitCompleteException {
393        checkInitComplete();
394        BusClient bc = DDS.getInstance().getAgent().getBusClient();
395        WakeupTopicUtil.publishIncrementWakeupPriorityEnable(bc, true, priority);
396    }
397
398    /**
399     * 关闭本地热词分级功能
400     */
401    public void disenableIncrementWakeupPriority(String priority) throws DDSNotInitCompleteException {
402        checkInitComplete();
403        BusClient bc = DDS.getInstance().getAgent().getBusClient();
404        WakeupTopicUtil.publishIncrementWakeupPriorityEnable(bc, false, priority);
405    }
406
407    private void checkInitComplete() throws DDSNotInitCompleteException {
408        if (DDS.getInstance().getInitStatus() != DDS.INIT_COMPLETE_FULL) {
409            throw new DDSNotInitCompleteException();
410        }
411    }
412
413    private void checkInitPartComplete() throws DDSNotInitCompleteException {
414        if (DDS.getInstance().getInitStatus() == DDS.INIT_COMPLETE_NONE) {
415            throw new DDSNotInitCompleteException();
416        }
417    }
418
419    private WakeupType getRealRemoveType(WakeupType oriType, List<WakeupWord> wakeupWordList) {
420        if (wakeupWordList != null && !wakeupWordList.isEmpty()) {
421            WakeupWord wakeupWord = wakeupWordList.get(0);
422            if (wakeupWord != null && TextUtils.equals("true", wakeupWord.getIncrementWord())) {
423                if (oriType == WakeupType.REMOVE_COMMAND) {
424                    oriType = WakeupType.REMOVE_COMMAND_INCREMENT;
425                } else if (oriType == WakeupType.REMOVE_SHORTCUT) {
426                    oriType = WakeupType.REMOVE_SHORTCUT_INCREMENT;
427                }
428            }
429        }
430        return oriType;
431    }
432
433    private boolean isWakeupIncrementTopic(List<WakeupWord> wakeupWordList) {
434        if (wakeupWordList != null && !wakeupWordList.isEmpty()) {
435            WakeupWord wakeupWord = wakeupWordList.get(0);
436            if (wakeupWord != null && TextUtils.equals("true", wakeupWord.getIncrementWord())) {
437                return true;
438            }
439        }
440        return false;
441    }
442
443    private WakeupType getRealWakeupType(WakeupType wakeupType, List<WakeupWord> wakeupWordList) {
444        if (wakeupWordList != null && !wakeupWordList.isEmpty()) {
445            WakeupWord wakeupWord = wakeupWordList.get(0);
446            if (wakeupWord != null && TextUtils.equals("true", wakeupWord.getIncrementWord())) {
447                switch (wakeupType) {
448                    case UPDATE_COMMAND:
449                        wakeupType = WakeupType.UPDATE_COMMAND_INCREMENT;
450                        break;
451                    case ADD_COMMAND:
452                        wakeupType = WakeupType.ADD_COMMAND_INCREMENT;
453                        break;
454                    case UPDATE_SHORTCUT:
455                        wakeupType = WakeupType.UPDATE_SHORTCUT_INCREMENT;
456                        break;
457                    case ADD_SHORTCUT:
458                        wakeupType = WakeupType.ADD_SHORTCUT_INCREMENT;
459                        break;
460                }
461            }
462        }
463        return wakeupType;
464    }
465
466    /**********************++@Deprecated++**************************/
467    /**
468     * 添加主唤醒词的接口
469     */
470    @Deprecated
471    public void addMainWakeupWord(String[] words, String[] pinyin, String[] threshold, String[][] greetings) throws DDSNotInitCompleteException {
472        checkInitComplete();
473        if (words == null)
474            throw new IllegalArgumentException("addMainWakeupWord words is null");
475        if (pinyin == null)
476            throw new IllegalArgumentException("addMainWakeupWord pinyin is null");
477        if (threshold == null)
478            throw new IllegalArgumentException("addMainWakeupWord threshold is null");
479        if (greetings == null)
480            throw new IllegalArgumentException("addMainWakeupWord greetings is null");
481        int length = words.length;
482        if (pinyin.length != length || threshold.length != length || greetings.length != length) {
483            throw new IllegalArgumentException("addMainWakeupWord array length  not the same");
484        }
485        BusClient bc = DDS.getInstance().getAgent().getBusClient();
486        if (bc != null) {
487            try {
488                JSONArray jsonArray = new JSONArray();
489                for (int i = 0; i < words.length; i++) {
490                    JSONObject jso = new JSONObject();
491                    jso.put("name", words[i]);
492                    jso.put("pinyin", pinyin[i]);
493                    jso.put("threshold", threshold[i]);
494                    if (greetings[i] != null) {
495                        JSONArray greetingArray = new JSONArray();
496                        for (int j = 0; j < greetings[i].length; j++) {
497                            greetingArray.put(greetings[i][j]);
498                        }
499                        jso.put("greeting", greetingArray);
500                    }
501                    jsonArray.put(jso);
502                }
503                AILog.d(TAG, "addMainWakeupWord : " + jsonArray);
504                WakeupTopicUtil.publishStickyUpdateMainword(bc, jsonArray, "add");
505            } catch (JSONException e) {
506                AILog.e(TAG, "addMainWakeupWord failed due to JSONException");
507                AIJavaException.printException(e);
508            }
509        } else {
510            AILog.e(TAG, "addMainWakeupWord failed due to null busclient");
511        }
512    }
513
514    /**
515     * 删除主唤醒词的接口
516     */
517    @Deprecated
518    public void removeMainWakeupWord(String[] words) throws DDSNotInitCompleteException {
519        checkInitComplete();
520        if (words == null)
521            throw new IllegalArgumentException("removeMainWakeupWord words is null");
522        BusClient bc = DDS.getInstance().getAgent().getBusClient();
523        if (bc != null) {
524            try {
525                JSONArray jsonArray = new JSONArray();
526                for (int i = 0; i < words.length; i++) {
527                    JSONObject jso = new JSONObject();
528                    jso.put("name", words[i]);
529                    jsonArray.put(jso);
530                }
531                AILog.d(TAG, "removeMainWakeupWord : " + jsonArray.toString());
532                WakeupTopicUtil.publishStickyUpdateMainword(bc, jsonArray, "remove");
533            } catch (JSONException e) {
534                AILog.e(TAG, "removeMainWakeupWord failed due to JSONException");
535                AIJavaException.printException(e);
536            }
537        } else {
538            AILog.e(TAG, "removeMainWakeupWord failed due to null busclient");
539        }
540    }
541
542    /**
543     * 更新副唤醒词的接口
544     */
545    @Deprecated
546    public void updateMinorWakeupWord(String word, String pinyin, String threshold, String[] greetings) throws
547            DDSNotInitCompleteException {
548        checkInitComplete();
549        BusClient bc = DDS.getInstance().getAgent().getBusClient();
550        if (bc != null) {
551            JSONObject obj = new JSONObject();
552            try {
553                if (null != word) {
554                    obj.put("name", word);
555                }
556                if (null != pinyin) {
557                    obj.put("pinyin", pinyin);
558                }
559                if (null != threshold) {
560                    obj.put("threshold", threshold);
561                }
562                if (null != greetings) {
563                    JSONArray greetingsArray = new JSONArray();
564                    for (String s : greetings) {
565                        greetingsArray.put(s);
566                    }
567                    obj.put("greeting", greetingsArray);
568                }
569            } catch (JSONException e) {
570                AILog.e(TAG, "updateMinorWakeupWord failed due to JSONException");
571                AIJavaException.printException(e);
572            }
573            WakeupTopicUtil.publishStickyRenameMinorWord(bc, obj);
574        } else {
575            AILog.e(TAG, "updateMinorWakeupWord failed due to null busclient");
576        }
577    }
578
579    /**
580     * 更新命令唤醒词的接口
581     */
582    @Deprecated
583    public void updateCommandWakeupWord(String[] actions, String[] words, String[] pinyin, String[] threshold, String[][] greetings) throws DDSNotInitCompleteException {
584        checkInitComplete();
585        if (actions == null)
586            throw new IllegalArgumentException("updateCommandWakeupWord actions is null");
587        if (words == null)
588            throw new IllegalArgumentException("updateCommandWakeupWord words is null");
589        if (pinyin == null)
590            throw new IllegalArgumentException("updateCommandWakeupWord pinyin is null");
591        if (threshold == null)
592            throw new IllegalArgumentException("updateCommandWakeupWord threshold is null");
593        if (greetings == null)
594            throw new IllegalArgumentException("updateCommandWakeupWord greetings is null");
595        int length = actions.length;
596        if (words.length != length || pinyin.length != length || threshold.length != length || greetings.length != length) {
597            throw new IllegalArgumentException("updateCommandWakeupWord array length  not the same");
598        }
599        BusClient bc = DDS.getInstance().getAgent().getBusClient();
600        if (bc != null) {
601            try {
602                JSONArray jsonArray = new JSONArray();
603                for (int i = 0; i < words.length; i++) {
604                    JSONObject jso = new JSONObject();
605                    jso.put("name", words[i]);
606                    jso.put("action", actions[i]);
607                    jso.put("pinyin", pinyin[i]);
608                    jso.put("threshold", threshold[i]);
609                    JSONArray greetingArray = new JSONArray();
610                    for (int j = 0; j < greetings[i].length; j++) {
611                        greetingArray.put(greetings[i][j]);
612                    }
613                    jso.put("greeting", greetingArray);
614                    jsonArray.put(jso);
615                }
616                AILog.d(TAG, "updateCommandWakeupWord : " + jsonArray);
617                WakeupTopicUtil.publishStickyUpdateCmdword(bc, false, jsonArray, "update");
618            } catch (JSONException e) {
619                AILog.e(TAG, "updateCommandWakeupWord failed due to JSONException");
620                AIJavaException.printException(e);
621            }
622
623
624        } else {
625            AILog.e(TAG, "updateCommandWakeupWord failed due to null busclient");
626        }
627    }
628
629    /**
630     * 添加命令唤醒词,且不会覆盖之前的命令唤醒词
631     */
632    @Deprecated
633    public void addCommandWakeupWord(String[] actions, String[] words, String[] pinyin, String[] threshold, String[][] greetings) throws DDSNotInitCompleteException {
634        checkInitComplete();
635        if (actions == null)
636            throw new IllegalArgumentException("addCommandWakeupWord actions is null");
637        if (words == null)
638            throw new IllegalArgumentException("addCommandWakeupWord words is null");
639        if (pinyin == null)
640            throw new IllegalArgumentException("addCommandWakeupWord pinyin is null");
641        if (threshold == null)
642            throw new IllegalArgumentException("addCommandWakeupWord threshold is null");
643        if (greetings == null)
644            throw new IllegalArgumentException("addCommandWakeupWord greetings is null");
645        int length = actions.length;
646        if (words.length != length || pinyin.length != length || threshold.length != length || greetings.length != length) {
647            throw new IllegalArgumentException("addCommandWakeupWord array length  not the same");
648        }
649        BusClient bc = DDS.getInstance().getAgent().getBusClient();
650        if (bc != null) {
651            try {
652                JSONArray jsonArray = new JSONArray();
653                for (int i = 0; i < words.length; i++) {
654                    JSONObject jso = new JSONObject();
655                    jso.put("name", words[i]);
656                    jso.put("action", actions[i]);
657                    jso.put("pinyin", pinyin[i]);
658                    jso.put("threshold", threshold[i]);
659                    JSONArray greetingArray = new JSONArray();
660                    for (int j = 0; j < greetings[i].length; j++) {
661                        greetingArray.put(greetings[i][j]);
662                    }
663                    jso.put("greeting", greetingArray);
664                    jsonArray.put(jso);
665                }
666                AILog.d(TAG, "addCommandWakeupWord : " + jsonArray);
667                WakeupTopicUtil.publishStickyUpdateCmdword(bc, false, jsonArray, "add");
668            } catch (JSONException e) {
669                AILog.e(TAG, "addCommandWakeupWord failed due to JSONException");
670                AIJavaException.printException(e);
671            }
672
673
674        } else {
675            AILog.e(TAG, "addCommandWakeupWord failed due to null busclient");
676        }
677    }
678
679
680    /**
681     * 移除指定的命令唤醒词
682     */
683    @Deprecated
684    public void removeCommandWakeupWord(String[] words) throws DDSNotInitCompleteException {
685        checkInitComplete();
686        if (words == null)
687            throw new IllegalArgumentException("removeCommandWakeupWord words is null");
688        BusClient bc = DDS.getInstance().getAgent().getBusClient();
689        if (bc != null) {
690            try {
691                JSONArray jsonArray = new JSONArray();
692                for (int i = 0; i < words.length; i++) {
693                    JSONObject jso = new JSONObject();
694                    jso.put("name", words[i]);
695                    jsonArray.put(jso);
696                }
697                AILog.d(TAG, "removeCommandWakeupWord : " + jsonArray.toString());
698                WakeupTopicUtil.publishStickyUpdateCmdword(bc, false, jsonArray, "remove");
699            } catch (JSONException e) {
700                AILog.e(TAG, "removeCommandWakeupWord failed due to JSONException");
701                AIJavaException.printException(e);
702            }
703
704        } else {
705            AILog.e(TAG, "removeCommandWakeupWord failed due to null busclient");
706        }
707    }
708
709    /**
710     * 更新打断唤醒词的接口,这类唤醒词能打断正在播报的语音并且将唤醒词送入识别
711     */
712    @Deprecated
713    public void updateShortcutWakeupWord(String[] words, String[] pinyin, String[] threshold) throws DDSNotInitCompleteException {
714        checkInitComplete();
715        if (words == null)
716            throw new IllegalArgumentException("updateShortcutWakeupWord words is null");
717        if (pinyin == null)
718            throw new IllegalArgumentException("updateShortcutWakeupWord pinyin is null");
719        if (threshold == null)
720            throw new IllegalArgumentException("updateShortcutWakeupWord threshold is null");
721        int length = words.length;
722        if (pinyin.length != length || threshold.length != length) {
723            throw new IllegalArgumentException("updateShortcutWakeupWord array length  not the same");
724        }
725        BusClient bc = DDS.getInstance().getAgent().getBusClient();
726        if (bc != null) {
727            try {
728                JSONArray jsonArray = new JSONArray();
729                for (int i = 0; i < words.length; i++) {
730                    JSONObject jso = new JSONObject();
731                    jso.put("name", words[i]);
732                    jso.put("pinyin", pinyin[i]);
733                    jso.put("threshold", threshold[i]);
734                    jsonArray.put(jso);
735                }
736                AILog.d(TAG, "updateShortcutWakeupWord : " + jsonArray);
737                WakeupTopicUtil.publishStickyUpdateFixword(bc, false, jsonArray, "update");
738            } catch (JSONException e) {
739                AILog.e(TAG, "updateShortcutWakeupWord failed due to JSONException");
740                AIJavaException.printException(e);
741            }
742        } else {
743            AILog.e(TAG, "updateShortcutWakeupWord failed due to null busclient");
744        }
745    }
746
747    /**
748     * 添加新的打断唤醒词,且不会覆盖之前的唤醒词
749     */
750    @Deprecated
751    public void addShortcutWakeupWord(String[] words, String[] pinyin, String[] threshold) throws DDSNotInitCompleteException {
752        checkInitComplete();
753        if (words == null)
754            throw new IllegalArgumentException("addShortcutWakeupWord words is null");
755        if (pinyin == null)
756            throw new IllegalArgumentException("addShortcutWakeupWord pinyin is null");
757        if (threshold == null)
758            throw new IllegalArgumentException("addShortcutWakeupWord threshold is null");
759        int length = words.length;
760        if (pinyin.length != length || threshold.length != length) {
761            throw new IllegalArgumentException("addShortcutWakeupWord array length  not the same");
762        }
763        BusClient bc = DDS.getInstance().getAgent().getBusClient();
764        if (bc != null) {
765            try {
766                JSONArray jsonArray = new JSONArray();
767                for (int i = 0; i < words.length; i++) {
768                    JSONObject jso = new JSONObject();
769                    jso.put("name", words[i]);
770                    jso.put("pinyin", pinyin[i]);
771                    jso.put("threshold", threshold[i]);
772                    jsonArray.put(jso);
773                }
774                AILog.d(TAG, "addShortcutWakeupWord : " + jsonArray);
775                WakeupTopicUtil.publishStickyUpdateFixword(bc, false, jsonArray, "add");
776            } catch (JSONException e) {
777                AILog.e(TAG, "addShortcutWakeupWord failed due to JSONException");
778                AIJavaException.printException(e);
779            }
780        } else {
781            AILog.e(TAG, "addShortcutWakeupWord failed due to null busclient");
782        }
783    }
784
785
786    /**
787     * 移除指定的打断唤醒词
788     */
789    @Deprecated
790    public void removeShortcutWakeupWord(String[] words) throws DDSNotInitCompleteException {
791        checkInitComplete();
792        if (words == null)
793            throw new IllegalArgumentException("removeShortcutWakeupWord words is null");
794        BusClient bc = DDS.getInstance().getAgent().getBusClient();
795        if (bc != null) {
796            try {
797                JSONArray jsonArray = new JSONArray();
798                for (int i = 0; i < words.length; i++) {
799                    JSONObject jso = new JSONObject();
800                    jso.put("name", words[i]);
801                    jsonArray.put(jso);
802                }
803                AILog.d(TAG, "removeShortcutWakeupWord : " + jsonArray);
804                WakeupTopicUtil.publishStickyUpdateFixword(bc, false, jsonArray, "remove");
805            } catch (JSONException e) {
806                AILog.e(TAG, "removeShortcutWakeupWord failed due to JSONException");
807                AIJavaException.printException(e);
808            }
809        } else {
810            AILog.e(TAG, "removeShortcutWakeupWord failed due to null busclient");
811        }
812    }
813
814    /**********************--@Deprecated--**************************/
815}