本文整理汇总了Java中android.speech.SpeechRecognizer.createSpeechRecognizer方法的典型用法代码示例。如果您正苦于以下问题:Java SpeechRecognizer.createSpeechRecognizer方法的具体用法?Java SpeechRecognizer.createSpeechRecognizer怎么用?Java SpeechRecognizer.createSpeechRecognizer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.speech.SpeechRecognizer
的用法示例。
在下文中一共展示了SpeechRecognizer.createSpeechRecognizer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SpeechRecognizerManager
import android.speech.SpeechRecognizer; //导入方法依赖的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.SpeechRecognizer; //导入方法依赖的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: StudentAdapterViewHolder
import android.speech.SpeechRecognizer; //导入方法依赖的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);
}
示例4: onCreate
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_robot);
//hide
ActionBar actionBar = getActionBar();
if (null != actionBar)
actionBar.hide();
mHandler = new responseHandler();
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new
ComponentName(
this, VoiceRecognitionService.class));
mSpeechRecognizer.setRecognitionListener(new
CustomRecognitionListener());
initVariables();
initData();
initView();
iniListener();
mSpeechSynthesizer = SpeakerUtils.getInstance(RobotActivity.this).initialTts();
}
示例5: initSpeechRecognizer
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
private void initSpeechRecognizer() {
Log.e(TAG, "initSpeechRecognizer: ");
Handler handler = getHandler();
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(mContext);
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,
mContext.getPackageName());
mSpeechRecognizer.setRecognitionListener(new SpeechListener(handler));
mSpeechRecognizer.startListening(recognizerIntent);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mSpeechRecognizer.stopListening();
}
}, DELAY_MILLIS);
}
示例6: createSpeechRecognizer
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
@ReactMethod
public void createSpeechRecognizer(final Promise promise) {
if (reactContext == null)
throw new IllegalArgumentException("ReactApplicationContext must be defined!");
if (mSpeechRecognizer != null) {
mSpeechRecognizer.destroy();
mSpeechRecognizer = null;
}
if (SpeechRecognizer.isRecognitionAvailable(reactContext)) {
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(reactContext);
mSpeechRecognizer.setRecognitionListener(new SpeechRecognitionListener(
this.reactContext.getJSModule(RCTNativeAppEventEmitter.class)
));
promise.resolve(null);
} else{
promise.reject("error", "SpeechRecognizer not available");
}
}
示例7: createRecognizer
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
public static SpeechRecognizer createRecognizer(AppCompatActivity activity, SpeechActionListener resultHandler, String wakeUpPhrase) {
speechRecognizer =
SpeechRecognizer.createSpeechRecognizer(activity);
loadingRecognizer = new ProgressDialog(activity, R.style.AppCompatAlertDialogStyle);
loadingRecognizer.setIndeterminate(true);
loadingRecognizer.setMessage("Starting up Voice Listener...");
loadingRecognizer.show();
speechRecognizer.setRecognitionListener(new SpeechListener(resultHandler));
wakeUpPhraseText = wakeUpPhrase;
textView = (TextView) activity.findViewById(R.id.spokenText);
intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, activity.getPackageName());
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "fr-FR");
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "fr-FR");
intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, "fr-FR");
intent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);
// intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 10000);
// intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 500);
// intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 2500);
// intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
speechRecognizer.startListening(intent);
return speechRecognizer;
}
示例8: recordVoice
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
@OnClick(R.id.fab_record)
public void recordVoice(View view){
//Set up
mHearingText.setVisibility(View.VISIBLE);
mHearingText.setAlpha(0f);
//Recording
recognizer = SpeechRecognizer.createSpeechRecognizer(getContext());
recognizer.setRecognitionListener(this);
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "it-IT");
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "it-IT");
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5);
recognizer.startListening(intent);
}
示例9: onCreate
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mHandler = new responseHandler();
// mManager = DatabaseManager.getIntance(MainActivity.this);
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new
ComponentName(
this, VoiceRecognitionService.class));
mSpeechRecognizer.setRecognitionListener(new
CustomRecognitionListener());
initData();
initView();
iniListener();
// loadData();
}
示例10: onCreate
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment VoiceInputFragment.
*/
// TODO: Rename and change types and number of parameters
// public static VoiceInputFragment newInstance(String param1, String param2) {
// VoiceInputFragment fragment = new VoiceInputFragment();
// Bundle args = new Bundle();
// args.putString(ARG_PARAM1, param1);
// args.putString(ARG_PARAM2, param2);
// fragment.setArguments(args);
// return fragment;
// }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(getContext(), new ComponentName(getContext(), VoiceRecognitionService.class));
mSpeechRecognizer.setRecognitionListener(this);
}
示例11: onStartCommand
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
stt_intent=intent;
//Initiate speechRecognizer object and start listening
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
speechRecognizer.setRecognitionListener(new SpeechListener(this,stt_intent));
speechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
speechRecognizer.startListening(speechRecognizerIntent);
Toast.makeText(this, "Speak now", Toast.LENGTH_LONG).show();
//start foreground notification
notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.skull)
.setContentTitle("DroidAssistant")
.setTicker("DroidAssistant")
.setLargeIcon(BitmapFactory.decodeResource(Resources.getSystem(), R.drawable.skull))
.setContentText(getString(R.string.sticker)).build();
startForeground(ONGOING_NOTIFICATION_ID, notification);
return Service.START_NOT_STICKY;
}
示例12: onCreate
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.textView);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
getPackageName());
mSpeechRecognizer.startListening(intent);
}
});
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
mSpeechRecognizer.setRecognitionListener(myRecognitionListener);
loadMemo();
}
示例13: onCreate
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.textView);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
getPackageName());
mSpeechRecognizer.startListening(intent);
}
});
//音声入力のプロバイダクラスを生成
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
mSpeechRecognizer.setRecognitionListener(myRecognitionListener);
loadMemo();
}
示例14: onCreate
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lesson35_activity_main);
mTextView = (TextView) findViewById(R.id.textView);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
getPackageName());
mSpeechRecognizer.startListening(intent);
}
});
//音声入力のプロバイダクラスを生成
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
mSpeechRecognizer.setRecognitionListener(myRecognitionListener);
loadMemo();
}
示例15: SpeechRecognition
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
private SpeechRecognition(long nativeSpeechRecognizerImplAndroid) {
mContinuous = false;
mNativeSpeechRecognizerImplAndroid = nativeSpeechRecognizerImplAndroid;
mListener = new Listener();
mIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
if (sRecognitionProvider != null) {
mRecognizer = SpeechRecognizer.createSpeechRecognizer(
ContextUtils.getApplicationContext(), sRecognitionProvider);
} else {
// It is possible to force-enable the speech recognition web platform feature (using a
// command-line flag) even if initialize() failed to find the PROVIDER_PACKAGE_NAME
// provider, in which case the first available speech recognition provider is used.
// Caveat: Continuous mode may not work as expected with a different provider.
mRecognizer =
SpeechRecognizer.createSpeechRecognizer(ContextUtils.getApplicationContext());
}
mRecognizer.setRecognitionListener(mListener);
}