根据官方文档写的唤醒demo报java.lang.Exception: WakeUpInitial=-1异常,唤醒功能一直用不了????
private static final String TAG = "WakeUpActivity";
private EventManager mWpEventManager;
private TextView text,log;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wake_up);
text = (TextView) findViewById(R.id.text);
log = (TextView) findViewById(R.id.log);
}
@Override
protected void onResume() {
super.onResume();
// 唤醒功能打开步骤
// 1) 创建唤醒事件管理器
mWpEventManager = EventManagerFactory.create(WakeUpActivity.this, "wp");
// 2) 注册唤醒事件监听器
mWpEventManager.registerListener(new EventListener() {
@Override
public void onEvent(String name, String params, byte[] data, int offset, int length) {
Log.d(TAG, String.format("event: name=%s, params=%s", name, params));
try {
JSONObject json = new JSONObject(params);
if ("wp.data".equals(name)) { // 每次唤醒成功, 将会回调name=wp.data的时间, 被激活的唤醒词在params的word字段
String word = json.getString("word");
Log.i(TAG,"唤醒成功, 唤醒词: " + word + "\r\n");
} else if ("wp.exit".equals(name)) {
Log.i(TAG,"唤醒已经停止: " + params + "\r\n");
}
} catch (JSONException e) {
throw new AndroidRuntimeException(e);
}
}
});
// 3) 通知唤醒管理器, 启动唤醒功能
HashMap params = new HashMap();
params.put("kws-file", "assets:///WakeUp.bin"); // 设置唤醒资源, 唤醒资源请到 http://yuyin.baidu.com/wake#m4 来评估和导出
mWpEventManager.send("wp.start", new JSONObject(params).toString(), null, 0, 0);
// txtLog.setText(DESC_TEXT);
}
@Override
protected void onPause() {
super.onPause();
// 停止唤醒监听
mWpEventManager.send("wp.stop", null, null, 0, 0);
}
}
收藏
点赞
0
个赞
请登录后评论
TOP
切换版块
TMTYang:
@fujiayi1984 在锤子 M1L 上跑 demo ,不能唤醒 ,报java.lang.Exception: WakeUpInitial=-1异常
回复TMTYang:
请在http://yuyin.baidu.com上新建一个应用测试官网demo,绑定包名com.baidu.speech.recognizerdemo
@fujiayi1984 在锤子 M1L 上跑 demo ,不能唤醒 ,报java.lang.Exception: WakeUpInitial=-1异常
哀叹这满心荒凉:
根据官方文档写的唤醒demo报java.lang.Exception: WakeUpInitial=-1异常,唤醒功能一直用不了????
public class WakeUpActivity extends AppCompatActivity {private static final String TAG = "WakeUpActivity";
private EventManager mWpEventManager;
private TextView text,log;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wake_up);
text = (TextView) findViewById(R.id.text);
log = (TextView) findViewById(R.id.log);
}
@Override
protected void onResume() {
super.onResume();
// 唤醒功能打开步骤
// 1) 创建唤醒事件管理器
mWpEventManager = EventManagerFactory.create(WakeUpActivity.this, "wp");
// 2) 注册唤醒事件监听器
mWpEventManager.registerListener(new EventListener() {
@Override
public void onEvent(String name, String params, byte[] data, int offset, int length) {
Log.d(TAG, String.format("event: name=%s, params=%s", name, params));
try {
JSONObject json = new JSONObject(params);
if ("wp.data".equals(name)) { // 每次唤醒成功, 将会回调name=wp.data的时间, 被激活的唤醒词在params的word字段
String word = json.getString("word");
Log.i(TAG,"唤醒成功, 唤醒词: " + word + "\r\n");
} else if ("wp.exit".equals(name)) {
Log.i(TAG,"唤醒已经停止: " + params + "\r\n");
}
} catch (JSONException e) {
throw new AndroidRuntimeException(e);
}
}
});
// 3) 通知唤醒管理器, 启动唤醒功能
HashMap params = new HashMap();
params.put("kws-file", "assets:///WakeUp.bin"); // 设置唤醒资源, 唤醒资源请到 http://yuyin.baidu.com/wake#m4 来评估和导出
mWpEventManager.send("wp.start", new JSONObject(params).toString(), null, 0, 0);
// txtLog.setText(DESC_TEXT);
}
@Override
protected void onPause() {
super.onPause();
// 停止唤醒监听
mWpEventManager.send("wp.stop", null, null, 0, 0);
}
}
回复哀叹这满心荒凉:您好,请测试下官网的2.1版本demo是否正常