當前位置: 首頁>>代碼示例>>Java>>正文


Java SpeechRecognizer.isRecognitionAvailable方法代碼示例

本文整理匯總了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");
  }
}
 
開發者ID:marshmelloX,項目名稱:react-native-stt,代碼行數:21,代碼來源:RNSpeechToText.java

示例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;
    }
}
 
開發者ID:jromero,項目名稱:AccessAbility4Glass,代碼行數:22,代碼來源:HandsFreeListView.java

示例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();
    }
}
 
開發者ID:Palo-IT,項目名稱:voice-IT,代碼行數:13,代碼來源:SpeechRecognizingActivity.java

示例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;
}
 
開發者ID:gotev,項目名稱:android-speech,代碼行數:30,代碼來源:Speech.java

示例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;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:33,代碼來源:SpeechRecognition.java

示例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!");
    }
}
 
開發者ID:ericleib,項目名稱:blindtale,代碼行數:16,代碼來源:GoogleSpeechAdapter.java

示例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());
    }
}
 
開發者ID:wso2-incubator,項目名稱:iot-server-agents,代碼行數:15,代碼來源:ListeningActivity.java

示例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;
}
 
開發者ID:qpliu,項目名稱:incant,代碼行數:14,代碼來源:Input.java

示例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;
}
 
開發者ID:shaeberling,項目名稱:winston,代碼行數:22,代碼來源:SpeechOperation.java

示例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;
}
 
開發者ID:openresearch,項目名稱:android-chromium-view,代碼行數:33,代碼來源:SpeechRecognition.java

示例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;
}
 
開發者ID:mogoweb,項目名稱:chromium_webview,代碼行數:38,代碼來源:SpeechRecognition.java

示例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());
}
 
開發者ID:hkuadithya,項目名稱:MovieManiac,代碼行數:4,代碼來源:MaterialSearchView.java

示例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;
}
 
開發者ID:Gauri-P,項目名稱:speech-recognition-android,代碼行數:8,代碼來源:speechRecognitionAndroid.java

示例15: isRecognitionAvailable

import android.speech.SpeechRecognizer; //導入方法依賴的package包/類
private boolean isRecognitionAvailable() {
  return SpeechRecognizer.isRecognitionAvailable(context);
}
 
開發者ID:pbakondy,項目名稱:cordova-plugin-speechrecognition,代碼行數:4,代碼來源:SpeechRecognition.java


注:本文中的android.speech.SpeechRecognizer.isRecognitionAvailable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。