001package com.aispeech.dui.dds.agent.wakeup.word;
002
003import android.text.TextUtils;
004
005import org.json.JSONObject;
006
007import java.util.ArrayList;
008import java.util.List;
009
010public class WakeupWord implements IWakeupWord {
011    protected String name;
012    protected String pinyin;
013    protected String threshold;
014    protected String threshold2;
015    protected List<String> greetingList = new ArrayList<>();
016    protected String action;
017    protected ICreateEngine mCreateEngine;
018    protected String dcheck;
019    protected String major;
020    protected String incrementWord = "false";// 是否是本地识别增量的词语,默认 “false”
021    private String priority = "0";
022
023
024    //双头唤醒相关参数
025    /**
026     * 设置双唤醒唤醒词是否使用自定义网络,"1"表示自定义网络,"0"表示主网络
027     */
028    private int customNet;
029
030    /**
031     * 设置双唤醒唤醒词对应的网络是否打开,"1"表示打开,"0"表示关闭
032     */
033    private int enableNet;
034
035    /**
036     * 设置双唤醒e2e低阈值,结合高阈值配套使用
037     */
038    private String threshLow;
039
040    /**
041     * 设置双唤醒e2e高阈值,结合低阈值配套使用
042     */
043    private String threshHigh;
044
045
046    /**
047     * 设置是否是本地识别增量词语
048     *
049     * @param incrementWord
050     */
051    public WakeupWord setIncrementWord(String incrementWord) {
052        this.incrementWord = incrementWord;
053        return this;
054    }
055
056    /**
057     * 设置唤醒词汉字
058     *
059     * @param word 唤醒词汉字
060     * @return
061     */
062    public WakeupWord setWord(String word) {
063        this.name = word;
064        return this;
065    }
066
067    /**
068     * 设置唤醒词拼音
069     *
070     * @param pinyin 唤醒词拼音
071     * @return
072     */
073    public WakeupWord setPinyin(String pinyin) {
074        this.pinyin = pinyin;
075        return this;
076    }
077
078    /**
079     * 设置唤醒词阈值
080     *
081     * @param threshold 唤醒词阈值
082     * @return
083     */
084    public WakeupWord setThreshold(String threshold) {
085        this.threshold = threshold;
086        return this;
087    }
088
089    /**
090     * 设置唤醒词阈值
091     *
092     * @param threshold  唤醒词阈值
093     * @param threshold2 唤醒词阈值2
094     * @return
095     */
096    public WakeupWord setThreshold(String threshold, String threshold2) {
097        this.threshold = threshold;
098        this.threshold2 = threshold2;
099        return this;
100    }
101
102    /**
103     * 添加唤醒词欢迎语
104     *
105     * @param greeting 唤醒词欢迎语
106     * @return
107     */
108    public WakeupWord addGreeting(String greeting) {
109        if (!TextUtils.isEmpty(greeting))
110            greetingList.add(greeting);
111        return this;
112    }
113
114    /**
115     * 设置唤醒词欢迎语
116     *
117     * @param greetingList 唤醒词欢迎语集合
118     * @return
119     */
120    public WakeupWord setGreetings(ArrayList<String> greetingList) {
121        if (greetingList != null && greetingList.size() > 0) {
122            this.greetingList = greetingList;
123        } else {
124            this.greetingList.clear();
125        }
126        return this;
127    }
128
129    /**
130     * 设置唤醒词对应的command命令
131     *
132     * @param action 唤醒词对应的command命令
133     * @return
134     */
135    public WakeupWord setAction(String action) {
136        this.action = action;
137        return this;
138    }
139
140    /**
141     * 设置唤醒校验
142     *
143     * @param dcheck
144     * @return
145     */
146    public WakeupWord setDcheck(String dcheck) {
147        this.dcheck = dcheck;
148        return this;
149    }
150
151    /**
152     * 设置热词优先级数值
153     *
154     * @param priority
155     */
156    public WakeupWord setPriority(String priority) {
157        this.priority = priority;
158        return this;
159    }
160
161
162    public WakeupWord setMajor(String major) {
163        this.major = major;
164        return this;
165    }
166
167
168    /**
169     * 设置双唤醒唤醒词是否使用自定义网络,"1"表示自定义网络,"0"表示主网络
170     *
171     * @param customNet
172     * @return
173     */
174    public WakeupWord setCustomNet(int customNet) {
175        this.customNet = customNet;
176        return this;
177    }
178
179    public WakeupWord setEnableNet(int enableNet) {
180        this.enableNet = enableNet;
181        return this;
182    }
183
184    public WakeupWord setThreshLow(String threshLow) {
185        this.threshLow = threshLow;
186        return this;
187    }
188
189    public WakeupWord setThreshHigh(String threshHigh) {
190        this.threshHigh = threshHigh;
191        return this;
192    }
193
194    protected JSONObject getJsonObject() {
195        return mCreateEngine.getJsonObject(this);
196    }
197
198    protected String getJson() {
199        JSONObject obj = getJsonObject();
200        if (obj != null) {
201            return obj.toString();
202        }
203        return null;
204    }
205
206    public String getName() {
207        return name;
208    }
209
210    public String getPinyin() {
211        return pinyin;
212    }
213
214    public String getThreshold() {
215        return threshold;
216    }
217
218    public String getThreshold2() {
219        return threshold2;
220    }
221
222    public List<String> getGreetingList() {
223        return greetingList;
224    }
225
226    public String getAction() {
227        return action;
228    }
229
230    public String getDcheck() {
231        return dcheck;
232    }
233
234    public String getMajor() {
235        return major;
236    }
237
238    public String getIncrementWord() {
239        return incrementWord;
240    }
241
242    public boolean isIncrementWord() {
243        return TextUtils.equals("true", incrementWord);
244    }
245
246    public String getPriority() {
247        return priority;
248    }
249
250    public int getCustomNet() {
251        return customNet;
252    }
253
254    public int getEnableNet() {
255        return enableNet;
256    }
257
258    public String getThreshLow() {
259        return threshLow;
260    }
261
262    public String getThreshHigh() {
263        return threshHigh;
264    }
265
266    @Override
267    public String toString() {
268        return "WakeupWord{" +
269                "name='" + name + '\'' +
270                ", pinyin='" + pinyin + '\'' +
271                ", threshold='" + threshold + '\'' +
272                ", threshold2='" + threshold2 + '\'' +
273                ", greetingList=" + greetingList +
274                ", action='" + action + '\'' +
275                ", mCreateEngine=" + mCreateEngine +
276                ", dcheck='" + dcheck + '\'' +
277                ", major='" + major + '\'' +
278                ", incrementWord='" + incrementWord + '\'' +
279                ", priority='" + priority + '\'' +
280                ", threshHigh='" + threshHigh + '\'' +
281                ", threshLow='" + threshLow + '\'' +
282                ", customNet='" + customNet + '\'' +
283                ", enableNet='" + enableNet + '\'' +
284                '}';
285    }
286
287    @Override
288    public void setCreateEngine(ICreateEngine createEngine) {
289        mCreateEngine = createEngine;
290    }
291}