Java Code Examples for android.speech.SpeechRecognizer#isRecognitionAvailable()

The following examples show how to use android.speech.SpeechRecognizer#isRecognitionAvailable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchActivity.java    From jellyfin-androidtv with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean isSpeechEnabled = SpeechRecognizer.isRecognitionAvailable(this);

    // Determine fragment to use
    Fragment searchFragment = isSpeechEnabled
            ? new LeanbackSearchFragment()
            : new TextSearchFragment();

    // Add fragment
    getSupportFragmentManager()
            .beginTransaction()
            .replace(android.R.id.content, searchFragment)
            .commit();
}
 
Example 2
Source File: Speech.java    From android-speech with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: SpeechRecognitionManager.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Creates a speech recognizer & checks if the user has voice recognition ability. */
private void createSpeechRecognizer() {
  // Checks if user can use voice recognition.
  speechRecognizer = SpeechRecognizer.createSpeechRecognizer(talkbackContext);
  if (!SpeechRecognizer.isRecognitionAvailable(talkbackContext)) {
    Toast.makeText(
            talkbackContext,
            talkbackContext.getString(R.string.voice_commands_no_voice_recognition_ability),
            Toast.LENGTH_SHORT)
        .show();
    return;
  }
}
 
Example 4
Source File: SpeechRecognition.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: SpeechRecognition.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example 6
Source File: SpeechRecognition.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example 7
Source File: SpeechToTextManagerImpl.java    From mirror with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isEnabled() {
    return mRecognizer != null && SpeechRecognizer.isRecognitionAvailable(mAppManager.getAppContext());
}
 
Example 8
Source File: SpeechRecognition.java    From cordova-plugin-speechrecognition with MIT License 4 votes vote down vote up
private boolean isRecognitionAvailable() {
  return SpeechRecognizer.isRecognitionAvailable(context);
}