本文整理汇总了Java中android.speech.SpeechRecognizer.isRecognitionAvailable方法的典型用法代码示例。如果您正苦于以下问题:Java SpeechRecognizer.isRecognitionAvailable方法的具体用法?Java SpeechRecognizer.isRecognitionAvailable怎么用?Java SpeechRecognizer.isRecognitionAvailable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.speech.SpeechRecognizer
的用法示例。
在下文中一共展示了SpeechRecognizer.isRecognitionAvailable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
}
示例2: initSpeechRecognition
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
private boolean initSpeechRecognition() {
if (SpeechRecognizer.isRecognitionAvailable(getContext())) {
mSpeechRecognizer = SpeechRecognizer
.createSpeechRecognizer(getContext());
mSpeechRecognizer.setRecognitionListener(mRecognitionListener);
mRecognizerIntent = new Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
getContext().getPackageName());
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mRecognizerIntent
.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
return true;
} else {
Log.e(TAG, "Speech Recognition not available on this device.");
return false;
}
}
示例3: onCreate
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean recognizerIntent = SpeechRecognitionUtil.isSpeechAvailable(this);
if (!recognizerIntent) {
this.speechNotAvailable();
}
boolean direct = SpeechRecognizer.isRecognitionAvailable(this);
if (!direct) {
this.directSpeechNotAvailable();
}
}
示例4: initSpeechRecognizer
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
private void initSpeechRecognizer(final Context context) {
if (context == null)
throw new IllegalArgumentException("context must be defined!");
mContext = context;
if (SpeechRecognizer.isRecognitionAvailable(context)) {
if (mSpeechRecognizer != null) {
try {
mSpeechRecognizer.destroy();
} catch (final Throwable exc) {
Logger.debug(Speech.class.getSimpleName(),
"Non-Fatal error while destroying speech. " + exc.getMessage());
} finally {
mSpeechRecognizer = null;
}
}
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(context);
mSpeechRecognizer.setRecognitionListener(mListener);
initDelayedStopListening(context);
} else {
mSpeechRecognizer = null;
}
mPartialData.clear();
mUnstableData = null;
}
示例5: initialize
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
/**
* This method must be called before any instance of SpeechRecognition can be created. It will
* query Android's package manager to find a suitable speech recognition provider that supports
* continuous recognition.
*/
// TODO(crbug.com/635567): Fix this properly.
@SuppressLint("WrongConstant")
public static boolean initialize(Context context) {
if (!SpeechRecognizer.isRecognitionAvailable(context)) return false;
PackageManager pm = context.getPackageManager();
Intent intent = new Intent(RecognitionService.SERVICE_INTERFACE);
final List<ResolveInfo> list = pm.queryIntentServices(intent, PackageManager.GET_SERVICES);
for (ResolveInfo resolve : list) {
ServiceInfo service = resolve.serviceInfo;
if (!service.packageName.equals(PROVIDER_PACKAGE_NAME)) continue;
if (PackageUtils.getPackageVersion(context, service.packageName)
< PROVIDER_MIN_VERSION) {
continue;
}
sRecognitionProvider = new ComponentName(service.packageName, service.name);
return true;
}
// If we reach this point, we failed to find a suitable recognition provider.
return false;
}
示例6: initialize
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
public void initialize(SpeechResource resource, Context context) throws Exception {
this.context = context;
if(SpeechRecognizer.isRecognitionAvailable(context)){
speech = SpeechRecognizer.createSpeechRecognizer(context.getApplicationContext());
speech.setRecognitionListener(this);
speechIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, resource.getLang().getDisplayName());
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, resource.getLang().getDisplayName());
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, resource.getLang().getDisplayName());
speechIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, context.getPackageName());
//SPEECH_INTENT.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
}else{
throw new Exception("Google Speech recognition is not supported!");
}
}
示例7: initSpeech
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
/**
* Initialize the speech.
*/
protected void initSpeech() {
if (sr == null) {
sr = SpeechRecognizer.createSpeechRecognizer(this);
if (!SpeechRecognizer.isRecognitionAvailable(context)) {
Toast.makeText(context, "Speech Recognition is not available",
Toast.LENGTH_LONG).show();
finish();
}
sr.setRecognitionListener(VoiceRecognitionListener.getInstance());
}
}
示例8: onStart
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
public void onStart() {
recognitionAvailable = SpeechRecognizer.isRecognitionAvailable(context);
if (!recognitionAvailable) {
return;
}
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(context);
speechRecognizer.setRecognitionListener(recognitionListener);
recognizerReady = true;
usingKeyboard = false;
usingKeyboardDone = false;
doingInput = false;
waitingForEvent = false;
}
示例9: startOperationRecognition
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
/**
* Starts to recognize voice operations if voice recognition is available
* {@link android.speech.SpeechRecognizer#isRecognitionAvailable(android.content.Context)}
*
* @return <code>true</code> the recognition of the voice operation was successful started<br>
* <code>false</code> the recognition of the voice operation wasn't started.
*/
@Override
public synchronized boolean startOperationRecognition() {
boolean wasStarted = false;
if (mIsListening == false && SpeechRecognizer.isRecognitionAvailable(mContext)) {
final Intent recognizerIntent = initializeRecognizerIntent();
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(mContext);
mSpeechRecognizer.setRecognitionListener(this);
mSpeechRecognizer.startListening(recognizerIntent);
wasStarted = true;
mIsListening = true;
LOG.info("voice recognition started...");
}
return wasStarted;
}
示例10: initialize
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
public static boolean initialize(Context context) {
if (!SpeechRecognizer.isRecognitionAvailable(context))
return false;
PackageManager pm = context.getPackageManager();
Intent intent = new Intent(RecognitionService.SERVICE_INTERFACE);
final List<ResolveInfo> list = pm.queryIntentServices(intent, PackageManager.GET_SERVICES);
for (ResolveInfo resolve : list) {
ServiceInfo service = resolve.serviceInfo;
if (!service.packageName.equals(PROVIDER_PACKAGE_NAME))
continue;
int versionCode;
try {
versionCode = pm.getPackageInfo(service.packageName, 0).versionCode;
} catch (NameNotFoundException e) {
continue;
}
if (versionCode < PROVIDER_MIN_VERSION)
continue;
mRecognitionProvider = new ComponentName(service.packageName, service.name);
return true;
}
// If we reach this point, we failed to find a suitable recognition provider.
return false;
}
示例11: initialize
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
/**
* This method must be called before any instance of SpeechRecognition can be created. It will
* query Android's package manager to find a suitable speech recognition provider that supports
* continuous recognition.
*/
public static boolean initialize(Context context) {
if (!SpeechRecognizer.isRecognitionAvailable(context))
return false;
PackageManager pm = context.getPackageManager();
Intent intent = new Intent(RecognitionService.SERVICE_INTERFACE);
final List<ResolveInfo> list = pm.queryIntentServices(intent, PackageManager.GET_SERVICES);
for (ResolveInfo resolve : list) {
ServiceInfo service = resolve.serviceInfo;
if (!service.packageName.equals(PROVIDER_PACKAGE_NAME))
continue;
int versionCode;
try {
versionCode = pm.getPackageInfo(service.packageName, 0).versionCode;
} catch (NameNotFoundException e) {
continue;
}
if (versionCode < PROVIDER_MIN_VERSION)
continue;
sRecognitionProvider = new ComponentName(service.packageName, service.name);
return true;
}
// If we reach this point, we failed to find a suitable recognition provider.
return false;
}
示例12: isRecognitionAvailable
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
@ReactMethod
public void isRecognitionAvailable(final Promise promise) {
boolean available = SpeechRecognizer.isRecognitionAvailable(this.reactContext);
Log.d(TAG, "isRecognitionAvailable: " + available);
promise.resolve(available);
}
开发者ID:de-code,项目名称:react-native-android-speech-recognizer,代码行数:7,代码来源:RNAndroidSpeechRecognizerModule.java
示例13: isVoiceAvailable
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
private boolean isVoiceAvailable() {
return isInEditMode() || SpeechRecognizer.isRecognitionAvailable(getContext());
}
示例14: DoInit
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
/**
* Initialize the speech recognizer by checking if one exists.
*/
private boolean DoInit() {
this.recognizerPresent = SpeechRecognizer.isRecognitionAvailable(this.cordova.getActivity().getBaseContext());
return this.recognizerPresent;
}
示例15: isRecognitionAvailable
import android.speech.SpeechRecognizer; //导入方法依赖的package包/类
private boolean isRecognitionAvailable() {
return SpeechRecognizer.isRecognitionAvailable(context);
}