当前位置: 首页>>代码示例>>Java>>正文


Java RecognizerIntent类代码示例

本文整理汇总了Java中android.speech.RecognizerIntent的典型用法代码示例。如果您正苦于以下问题:Java RecognizerIntent类的具体用法?Java RecognizerIntent怎么用?Java RecognizerIntent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RecognizerIntent类属于android.speech包,在下文中一共展示了RecognizerIntent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SpeechRecognizerManager

import android.speech.RecognizerIntent; //导入依赖的package包/类
public SpeechRecognizerManager(Context context,onResultsReady listener)
{
    try{
        mListener=listener;
    }
    catch(ClassCastException e)
    {
        Log.e(TAG,e.toString());
    }
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(context);
    mSpeechRecognizer.setRecognitionListener(new SpeechRecognitionListener());
    mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
            context.getPackageName());
    startListening();

}
 
开发者ID:panda919,项目名称:AndroidVoiceRecognitionPanda,代码行数:21,代码来源:SpeechRecognizerManager.java

示例2: onCreate

import android.speech.RecognizerIntent; //导入依赖的package包/类
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mHeadPhoneListener = new HeadPhoneListener();
        mSpeechStateView = (TextView) findViewById(R.id.stateTextView);

        updateUI();

        /*
         *  Init Speech Recognizer
         */
        final SpeechRecognizer recognizer = SpeechRecognizer
                .createSpeechRecognizer(MainActivity.this);
        final Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        recognizerIntent.putExtra(
                RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName());
//        recognizer.setRecognitionListener(this);
        recognizer.setRecognitionListener(new SpeechListener(mHandler));

//        onClick(recognizer, recognizerIntent);
        permissionsCheck();
        registerForIntent();
    }
 
开发者ID:shashi2459,项目名称:notify-me,代码行数:27,代码来源:MainActivity.java

示例3: onActivityResult

import android.speech.RecognizerIntent; //导入依赖的package包/类
/**
 * Receiving speech input
 * */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
        case REQ_CODE_SPEECH_INPUT: {
            if (resultCode == RESULT_OK && null != data) {

                ArrayList<String> result = data
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                txtSpeechInput.setText(result.get(0));
            }
            break;
        }

    }
}
 
开发者ID:Captwalloper,项目名称:NUI_Project,代码行数:21,代码来源:VoiceActivity.java

示例4: onActivityResult

import android.speech.RecognizerIntent; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case RESULT_SPEECH: {
            if (resultCode == RESULT_OK && null != data) {

                ArrayList<String> text = data
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

                autoCompleteTextView.setText(text.get(0));
            }
            break;
        }

    }
}
 
开发者ID:Mun0n,项目名称:MADBike,代码行数:18,代码来源:SearchActivity.java

示例5: StudentAdapterViewHolder

import android.speech.RecognizerIntent; //导入依赖的package包/类
StudentAdapterViewHolder(View itemView) {
    super(itemView);
    studentImage = (ImageView) itemView.findViewById(R.id.f_data_student_profile);
    studentDetail = (TextView) itemView.findViewById(R.id.input_cardview_name);
    editText = (EditText) itemView.findViewById(R.id.input_cardview_score);
    layout = (LinearLayout) itemView.findViewById(R.id.input_cardview_layout);
    txInit = (TextView) itemView.findViewById(R.id.input_cardview_init);
    btnMic = (ToggleButton) itemView.findViewById(R.id.input_cardview_mic);
    progressBar = (ProgressBar) itemView.findViewById(R.id.progressBarney);
    btnMic.setOnCheckedChangeListener(this);

    speech = SpeechRecognizer.createSpeechRecognizer(context);
    speech.setRecognitionListener(this);
    recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, context.getPackageName());
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
}
 
开发者ID:inteliedoit,项目名称:thesis-project,代码行数:20,代码来源:ExamInputAdapter.java

示例6: onActivityResult

import android.speech.RecognizerIntent; //导入依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == Activity.RESULT_OK)
    {
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        if (matches != null && matches.size() > 0)
        {
            String searchWrd = matches.get(0);
            if (!TextUtils.isEmpty(searchWrd))
            {
                mSearchView.setQuery(searchWrd, false);
            }
        }
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
开发者ID:WeDevelopTeam,项目名称:HeroVideo-master,代码行数:19,代码来源:HomePageFragment.java

示例7: startVoiceRecognition

import android.speech.RecognizerIntent; //导入依赖的package包/类
void startVoiceRecognition() {
    try{
        //通过Intent传递语音识别的模式,开启语音
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        //语言模式和自由模式的语音识别
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        //提示语音开始
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "开始语音");
        //开始语音识别
        startActivityForResult(intent, VOICE_SEARCH_CODE);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), "找不到语音设备", 1).show();
    }
}
 
开发者ID:aliyun,项目名称:aliyun-cloudphotos-android-demo,代码行数:17,代码来源:MainActivity.java

示例8: retrieveInputFromUser

import android.speech.RecognizerIntent; //导入依赖的package包/类
@Override
public void retrieveInputFromUser(Fragment fragment) {
    ensurePermission(fragment);

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            fragment.getString(R.string.speech_prompt));
    try {
        fragment.startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        setFailureMessage(fragment.getString(R.string.speech_not_supported));
    }
}
 
开发者ID:Captwalloper,项目名称:NUI_Project,代码行数:17,代码来源:VoiceListener.java

示例9: getResult

import android.speech.RecognizerIntent; //导入依赖的package包/类
public VoiceResult getResult(int resultCode, Intent data) {
    if (hasFailureMessage()) {
        String message = popErrorMessage();
        return new VoiceResult(false, message);
    }
    else if (resultCode == RESULT_OK && null != data) {
        ArrayList<String> result = data
                .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        String value = result.get(0);
        return new VoiceResult(true, value);
    }
    else {
        throw new RuntimeException("VoiceListener failed to return an expected result.");
    }
}
 
开发者ID:Captwalloper,项目名称:NUI_Project,代码行数:16,代码来源:VoiceListener.java

示例10: promptSpeechInput

import android.speech.RecognizerIntent; //导入依赖的package包/类
/**
 * Showing google speech input dialog
 * */
private void promptSpeechInput() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:Captwalloper,项目名称:NUI_Project,代码行数:19,代码来源:VoiceActivity.java

示例11: retrievePotentialMedicineNameFromVoiceRecognizedData

import android.speech.RecognizerIntent; //导入依赖的package包/类
private String retrievePotentialMedicineNameFromVoiceRecognizedData(Intent data) {
    List<String> voiceRecognizedData = data
            .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

    String potentialMedicineName = voiceRecognizedData.get(0);
    return potentialMedicineName;
}
 
开发者ID:lmnpWmi,项目名称:wirtualnaApteczka,代码行数:8,代码来源:AddMedicineActivity.java

示例12: onClick

import android.speech.RecognizerIntent; //导入依赖的package包/类
@Override
public void onClick(View v) {
    Context context = v.getContext();

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            context.getString(R.string.speech_prompt));
    try {
        boolean isExecutedFromAddMedicine = context instanceof AddMedicineActivity;
        boolean isExecutedFromMedicineList = context instanceof MedicineListActivity;

        if (isExecutedFromAddMedicine) {
            ((AddMedicineActivity) context).startActivityForResult(intent, requestCode);
        }
        else if (isExecutedFromMedicineList) {
            ((MedicineListActivity) context).startActivityForResult(intent, requestCode);
        }
    } catch (ActivityNotFoundException a) {
        Toast.makeText(context,
                context.getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:lmnpWmi,项目名称:wirtualnaApteczka,代码行数:27,代码来源:LaunchVoiceRecognitionOnClickListener.java

示例13: onAutoPressed

import android.speech.RecognizerIntent; //导入依赖的package包/类
@OnClick(R.id.autoButton)
public void onAutoPressed() {
    if (clear) {
        autoCompleteTextView.setText("");
    } else {
        Intent intent = new Intent(
                RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, Locale.getDefault().getDisplayLanguage());

        try {
            startActivityForResult(intent, RESULT_SPEECH);
            autoCompleteTextView.setText("");
        } catch (ActivityNotFoundException a) {
            notificationManager.showMessage(getString(R.string.error_no_mic));
        }
    }
}
 
开发者ID:Mun0n,项目名称:MADBike,代码行数:19,代码来源:SearchActivity.java

示例14: onActivityResult

import android.speech.RecognizerIntent; //导入依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

  if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == Activity.RESULT_OK) {
    ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    if (matches != null && matches.size() > 0) {
      String searchWrd = matches.get(0);
      if (!TextUtils.isEmpty(searchWrd)) {
        mSearchView.setQuery(searchWrd, false);
      }
    }

    return;
  }
  super.onActivityResult(requestCode, resultCode, data);
}
 
开发者ID:MUFCRyan,项目名称:BilibiliClient,代码行数:17,代码来源:HomePageFragment.java

示例15: onSpeakButtonClick

import android.speech.RecognizerIntent; //导入依赖的package包/类
@OnClick(R.id.btnSpeak)
public void onSpeakButtonClick() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:vixir,项目名称:Perfect-Day,代码行数:17,代码来源:CreateTaskBySpeech.java


注:本文中的android.speech.RecognizerIntent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。