本文整理匯總了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();
}
}