Example #1
0
        public void onResult(RecognizerResult results, boolean isLast) {

          Log.e(">>>>>>>解析>>>>>>>>", results.getResultString());

          String text = JsonParser.parseIatResult(results.getResultString());
          // 向服务器发送消息
          if (text != null && text != "") {
            center.setText(text);
            Log.e("----------", text);
            if (text != null && !text.equals("")) {
              socket.sendMessage(DataParse.toJson("register", "admin", text));
            } else {
              socket.sendMessage(DataParse.toJson("register", "admin", "用户没有说话"));
            }
          }
          try {
            Thread.sleep(3000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }

          // 唤醒语音播放
          String callbackresult = socket.getMessage();
          if (callbackresult.contains("0x5a")) {
            Message msg = new Message();
            msg.what = 0;
            msg.obj = callbackresult;
            handler.sendMessage(msg);
          }
        }
Example #2
0
        @Override
        public void onResult(RecognizerResult results, boolean isLast) {
          String text = JsonParser.parseIatResult(results.getResultString());
          center.setText(text);
          if (isLast) {
            // TODO 最后的结果

          }
        }
        public void onResult(RecognizerResult results, boolean isLast) {
          String result = JsonParser.parseIatResult(results.getResultString());
          if (!TextUtils.isEmpty(result)) {
            if (result.contains("。")) {
              result = result.substring(0, (result.length() - 1));
            }

            if (!TextUtils.isEmpty(result)) {
              updateList4Voice(result);
            }
          }
        }
        // 听写结果回调接口(返回Json格式结果,用户可参见附录12.1);
        // 一般情况下会通过onResults接口多次返回结果,完整的识别内容是多次结果的累加;
        // 关于解析Json的代码可参见MscDemo中JsonParser类;
        // isLast等于true时会话结束。
        public void onResult(RecognizerResult results, boolean isLast) {

          StringBuffer resultBuffer = new StringBuffer();
          if (results != null) {
            String text = JsonParser.parseIatResult(results.getResultString());

            String sn = null;
            // 读取json结果中的sn字段
            try {
              JSONObject resultJson = new JSONObject(results.getResultString());
              sn = resultJson.optString("sn");
            } catch (JSONException e) {
              e.printStackTrace();
            }
            mIatResults.put(sn, text);

            for (String key : mIatResults.keySet()) {
              resultBuffer.append(mIatResults.get(key));
            }
          }
          if (isLast && mListener != null) {
            mListener.onParseString(resultBuffer.toString());
          }
        }