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