本文整理汇总了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();
}
示例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();
}
示例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;
}
}
}
示例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;
}
}
}
示例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);
}
示例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);
}
示例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();
}
}
示例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));
}
}
示例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.");
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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));
}
}
}
示例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);
}
示例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();
}
}