android sdk 一直返回2100
vigiles 发布于2018-09-19 15:41 浏览:325 回复:1
0
收藏

   

@BindView(R.id.recordTextView)
TextView recordTextView;

private EventManager asr;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    initView();
}

public void initView() {
    initBaidu();
    initEvent();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    asr.send(SpeechConstant.ASR_CANCEL, null, null, 0, 0);  // 取消识别
    asr.unregisterListener(speechEventListener);
}

private void initBaidu() {
    asr = EventManagerFactory.create(this, "asr");
    asr.registerListener(speechEventListener);
}

private void initEvent() {
    recordTextView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            int action = motionEvent.getAction();
            switch (action) {
                case MotionEvent.ACTION_DOWN: {
                    start();
                    return true;
                }
                case MotionEvent.ACTION_UP: {
                    stop();
                    return true;
                }
            }

            return false;
        }
    });
}

private void start() {
    Map params = new LinkedHashMap();
    params.put(SpeechConstant.DECODER, 0); // 0:在线
    params.put(SpeechConstant.ACCEPT_AUDIO_VOLUME, false);
    params.put(SpeechConstant.VAD_ENDPOINT_TIMEOUT, 0);
    params.put(SpeechConstant.VAD, SpeechConstant.VAD_DNN);
    params.put(SpeechConstant.PID, 1537);
    String json = new JSONObject(params).toString();
    asr.send(SpeechConstant.ASR_START, json, null, 0, 0);
}
 
private void stop() {
    asr.send(SpeechConstant.ASR_STOP, null, null, 0, 0); //
}

EventListener speechEventListener = new EventListener() {
    @Override
    public void onEvent(String name, String params, byte[] data, int offset, int length) {
        Log.e("ard", "ASR状态:" + name);
        Log.e("ard", "ASR参数:" + params);

        if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_READY)) {
            // 引擎就绪,可以说话,一般在收到此事件后通过UI通知用户可以说话了
        } else if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_FINISH)) {
            // 识别结束
        }
    }
};

我在做纯在线语音识别。请教下,权限都授予了,网络是正常的。但是录音即返回2100失败状态。

 E/ard: ASR状态:asr.finish
 E/ard: ASR参数:{"origin_result":{"sn":"","error":2,"desc":"Network is not available","sub_error":2100},"error":2,"desc":"Network is not available","sub_error":2100}
 E/ard: ASR状态:asr.exit
 E/ard: ASR参数:{"origin_result":{"sn":"","error":2,"desc":"Network is not available","sub_error":2100},"error":2,"desc":"Network is not available","sub_error":2100}

请教这是什么原因导致的。

 

收藏
点赞
0
个赞
共1条回复 最后由fujiayi1984回复于2018-09-19 15:47
#2fujiayi1984回复于2018-09-19 15:47:42

请测试下demo,是否有问题

0
TOP
切换版块