Exemplo n.º 1
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   // 退出时释放连接
   mSpeechUnderstander.cancel();
   mSpeechUnderstander.destroy();
   if (mTextUnderstander.isUnderstanding()) mTextUnderstander.cancel();
   mTextUnderstander.destroy();
 }
Exemplo n.º 2
0
  @Override
  public void onClick(View view) {
    switch (view.getId()) {
        // 进入参数设置页面
      case R.id.image_understander_set:
        Intent intent = new Intent(UnderstanderDemo.this, UnderstanderSettings.class);
        startActivity(intent);
        break;
        // 开始文本理解
      case R.id.text_understander:
        mUnderstanderText.setText("");
        String text = "合肥明天的天气怎么样?";
        showTip(text);

        if (mTextUnderstander.isUnderstanding()) {
          mTextUnderstander.cancel();
          showTip("取消");
        } else {
          ret = mTextUnderstander.understandText(text, textListener);
          if (ret != 0) {
            showTip("语义理解失败,错误码:" + ret);
          }
        }
        break;
        // 开始语音理解
      case R.id.start_understander:
        mUnderstanderText.setText("");
        // 设置参数
        setParam();

        if (mSpeechUnderstander.isUnderstanding()) { // 开始前检查状态
          mSpeechUnderstander.stopUnderstanding();
          showTip("停止录音");
        } else {
          ret = mSpeechUnderstander.startUnderstanding(mRecognizerListener);
          if (ret != 0) {
            showTip("语义理解失败,错误码:" + ret);
          } else {
            showTip(getString(R.string.text_begin));
          }
        }
        break;
        // 停止语音理解
      case R.id.understander_stop:
        mSpeechUnderstander.stopUnderstanding();
        showTip("停止语义理解");
        break;
        // 取消语音理解
      case R.id.understander_cancel:
        mSpeechUnderstander.cancel();
        showTip("取消语义理解");
        break;
      default:
        break;
    }
  }
 public void cancel() {
   m_understander.cancel();
 }