当前位置: 首页>>代码示例>>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;未经允许,请勿转载。