当前位置: 首页>>代码示例>>Java>>正文


Java SpeechRecognizer类代码示例

本文整理汇总了Java中android.speech.SpeechRecognizer的典型用法代码示例。如果您正苦于以下问题:Java SpeechRecognizer类的具体用法?Java SpeechRecognizer怎么用?Java SpeechRecognizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SpeechRecognizer类属于android.speech包,在下文中一共展示了SpeechRecognizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SpeechRecognizerManager

import android.speech.SpeechRecognizer; //导入依赖的package包/类
public SpeechRecognizerManager(Context context,onResultsReady listener)
{
    try{
        mListener=listener;
    }
    catch(ClassCastException e)
    {
        Log.e(TAG,e.toString());
    }
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(context);
    mSpeechRecognizer.setRecognitionListener(new SpeechRecognitionListener());
    mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
            context.getPackageName());
    startListening();

}
 
开发者ID:panda919,项目名称:AndroidVoiceRecognitionPanda,代码行数:21,代码来源:SpeechRecognizerManager.java

示例2: onCreate

import android.speech.SpeechRecognizer; //导入依赖的package包/类
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mHeadPhoneListener = new HeadPhoneListener();
        mSpeechStateView = (TextView) findViewById(R.id.stateTextView);

        updateUI();

        /*
         *  Init Speech Recognizer
         */
        final SpeechRecognizer recognizer = SpeechRecognizer
                .createSpeechRecognizer(MainActivity.this);
        final Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        recognizerIntent.putExtra(
                RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName());
//        recognizer.setRecognitionListener(this);
        recognizer.setRecognitionListener(new SpeechListener(mHandler));

//        onClick(recognizer, recognizerIntent);
        permissionsCheck();
        registerForIntent();
    }
 
开发者ID:shashi2459,项目名称:notify-me,代码行数:27,代码来源:MainActivity.java

示例3: StudentAdapterViewHolder

import android.speech.SpeechRecognizer; //导入依赖的package包/类
StudentAdapterViewHolder(View itemView) {
    super(itemView);
    studentImage = (ImageView) itemView.findViewById(R.id.f_data_student_profile);
    studentDetail = (TextView) itemView.findViewById(R.id.input_cardview_name);
    editText = (EditText) itemView.findViewById(R.id.input_cardview_score);
    layout = (LinearLayout) itemView.findViewById(R.id.input_cardview_layout);
    txInit = (TextView) itemView.findViewById(R.id.input_cardview_init);
    btnMic = (ToggleButton) itemView.findViewById(R.id.input_cardview_mic);
    progressBar = (ProgressBar) itemView.findViewById(R.id.progressBarney);
    btnMic.setOnCheckedChangeListener(this);

    speech = SpeechRecognizer.createSpeechRecognizer(context);
    speech.setRecognitionListener(this);
    recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, context.getPackageName());
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
}
 
开发者ID:inteliedoit,项目名称:thesis-project,代码行数:20,代码来源:ExamInputAdapter.java

示例4: onResults

import android.speech.SpeechRecognizer; //导入依赖的package包/类
@Override
public void onResults(Bundle results) {
    ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    int number = 0;
    for (String result : matches) {
        try {
            number = Integer.parseInt(result);
            break;
        } catch (NumberFormatException e) {
            e.printStackTrace();
            number = 0;
        }
    }
    editText.setText(number + "");
    isActivated = false;
}
 
开发者ID:inteliedoit,项目名称:thesis-project,代码行数:17,代码来源:ActivityInputAdapter.java

示例5: onCreate

import android.speech.SpeechRecognizer; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_robot);
    //hide
    ActionBar actionBar = getActionBar();
    if (null != actionBar)
        actionBar.hide();

    mHandler = new responseHandler();
    mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this, new
            ComponentName(
            this, VoiceRecognitionService.class));
    mSpeechRecognizer.setRecognitionListener(new
            CustomRecognitionListener());
    initVariables();
    initData();
    initView();
    iniListener();
    mSpeechSynthesizer = SpeakerUtils.getInstance(RobotActivity.this).initialTts();

}
 
开发者ID:AleGogogo,项目名称:MaoMaoRobot,代码行数:23,代码来源:RobotActivity.java

示例6: initSpeechRecognizer

import android.speech.SpeechRecognizer; //导入依赖的package包/类
private void initSpeechRecognizer() {
    Log.e(TAG, "initSpeechRecognizer: ");

    Handler handler = getHandler();

    mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(mContext);
    final Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    recognizerIntent.putExtra(
            RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
            mContext.getPackageName());

    mSpeechRecognizer.setRecognitionListener(new SpeechListener(handler));
    mSpeechRecognizer.startListening(recognizerIntent);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            mSpeechRecognizer.stopListening();
        }
    }, DELAY_MILLIS);
}
 
开发者ID:shashi2459,项目名称:notify-me,代码行数:22,代码来源:HeadPhoneListener.java

示例7: 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

示例8: showPlayServicesError

import android.speech.SpeechRecognizer; //导入依赖的package包/类
private void showPlayServicesError(final int errorCode) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "showPlayServicesError");
    }

    onError(SpeechRecognizer.ERROR_CLIENT);

    switch (errorCode) {

        case UNRECOVERABLE:
            // TODO
            break;
        default:
            final GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
            apiAvailability.showErrorNotification(mContext, errorCode);
            break;
    }
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:19,代码来源:RecognitionGoogleCloud.java

示例9: onError

import android.speech.SpeechRecognizer; //导入依赖的package包/类
/**
 * Receives a terminating error from the stream.
 * <p>
 * <p>May only be called once and if called it must be the last method called. In particular if an
 * exception is thrown by an implementation of {@code onError} no further calls to any method are
 * allowed.
 * <p>
 * <p>{@code t} should be a {@link StatusException} or {@link
 * StatusRuntimeException}, but other {@code Throwable} types are possible. Callers should
 * generally convert from a {@link Status} via {@link Status#asException()} or
 * {@link Status#asRuntimeException()}. Implementations should generally convert to a
 * {@code Status} via {@link Status#fromThrowable(Throwable)}.
 *
 * @param throwable the error occurred on the stream
 */
@Override
public void onError(final Throwable throwable) {
    if (DEBUG) {
        MyLog.w(CLS_NAME, "onError");
        throwable.printStackTrace();
        final Status status = Status.fromThrowable(throwable);
        MyLog.w(CLS_NAME, "onError: " + status.toString());
    }

    if (doError.get()) {
        doError.set(false);
        stopListening();
        listener.onError(SpeechRecognizer.ERROR_NETWORK);
    }
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:31,代码来源:RecognitionGoogleCloud.java

示例10: onError

import android.speech.SpeechRecognizer; //导入依赖的package包/类
/**
 * A network or recognition error occurred.
 *
 * @param error code is defined in {@link SpeechRecognizer}
 */
@Override
public void onError(final int error) {
    if (DEBUG) {
        MyLog.w(CLS_NAME, "onError: " + error);
        MyLog.w(CLS_NAME, "onError: doEndOfSpeech: " + doEndOfSpeech);
        MyLog.w(CLS_NAME, "onError: doError: " + doError);
        MyLog.i(CLS_NAME, "onError: doBeginningOfSpeech: " + doBeginningOfSpeech);
    }

    if (error != SpeechRecognizer.ERROR_NO_MATCH) {
        doError = true;
    }

    if (doError) {
        onRecognitionError(error);
    }
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:23,代码来源:SaiyRecognitionListener.java

示例11: putResults

import android.speech.SpeechRecognizer; //导入依赖的package包/类
/**
 * Add the recognition results to the existing {@link Bundle}
 *
 * @param results recognition results {@link Bundle}
 */
public void putResults(@NonNull final Bundle results) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "putResults");
    }

    final ArrayList<String> heardVoice = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    final float[] confidence = results.getFloatArray(SpeechRecognizer.CONFIDENCE_SCORES);

    if (heardVoice != null) {
        getBundle().putStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION, heardVoice);
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "putResults: speech empty");
        }
        getBundle().putStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION, new ArrayList<String>());
    }

    if (confidence != null) {
        getBundle().putFloatArray(SpeechRecognizer.CONFIDENCE_SCORES, confidence);
    } else {
        if (DEBUG) {
            MyLog.i(CLS_NAME, "putResults: confidence empty");
        }
        getBundle().putFloatArray(SpeechRecognizer.CONFIDENCE_SCORES, new float[0]);
    }
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:32,代码来源:SelfAwareConditions.java

示例12: process

import android.speech.SpeechRecognizer; //导入依赖的package包/类
/**
 * Process the extracted text as identified as a command
 *
 * @param text the command to process
 */
private void process(@NonNull final String text) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "process");
    }

    final Bundle bundle = new Bundle();

    final ArrayList<String> voiceResults = new ArrayList<>(1);
    voiceResults.add(text);

    final float[] confidence = new float[1];
    confidence[0] = 1f;

    bundle.putStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION, voiceResults);
    bundle.putFloatArray(SpeechRecognizer.CONFIDENCE_SCORES, confidence);
    bundle.putInt(LocalRequest.EXTRA_CONDITION, Condition.CONDITION_GOOGLE_NOW);

    AsyncTask.execute(new Runnable() {
        @Override
        public void run() {
            new RecognitionAction(SaiyAccessibilityService.this.getApplicationContext(), SPH.getVRLocale(SaiyAccessibilityService.this.getApplicationContext()),
                    SPH.getTTSLocale(SaiyAccessibilityService.this.getApplicationContext()), sl, bundle);
        }
    });
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:31,代码来源:SaiyAccessibilityService.java

示例13: onError

import android.speech.SpeechRecognizer; //导入依赖的package包/类
@Override
public void onError(int errorCode) {
    Log.d(TAG, "in onError");
    if ((errorCode == SpeechRecognizer.ERROR_NO_MATCH) || (errorCode == SpeechRecognizer.ERROR_SPEECH_TIMEOUT)) {
        stop();
        Log.d(TAG, "didn't recognize anything");
        // keep going
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        recognizeSpeechDirectly();
    } else {
        Log.d(TAG, "FAILED " + SpeechRecognitionUtil.diagnoseErrorCode(errorCode));
    }
}
 
开发者ID:Palo-IT,项目名称:voice-IT,代码行数:18,代码来源:WordActivator.java

示例14: createRecognizer

import android.speech.SpeechRecognizer; //导入依赖的package包/类
public static SpeechRecognizer createRecognizer(AppCompatActivity activity, SpeechActionListener resultHandler, String wakeUpPhrase) {
        speechRecognizer =
                SpeechRecognizer.createSpeechRecognizer(activity);
        loadingRecognizer = new ProgressDialog(activity, R.style.AppCompatAlertDialogStyle);
        loadingRecognizer.setIndeterminate(true);
        loadingRecognizer.setMessage("Starting up Voice Listener...");
        loadingRecognizer.show();
        speechRecognizer.setRecognitionListener(new SpeechListener(resultHandler));
        wakeUpPhraseText = wakeUpPhrase;
        textView = (TextView) activity.findViewById(R.id.spokenText);
        intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, activity.getPackageName());
        intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "fr-FR");
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "fr-FR");
        intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, "fr-FR");
        intent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);
//        intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 10000);
//        intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 500);
//        intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 2500);
//            intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
        speechRecognizer.startListening(intent);
        return speechRecognizer;
    }
 
开发者ID:Palo-IT,项目名称:voice-IT,代码行数:26,代码来源:SpeechToTextAction.java

示例15: onError

import android.speech.SpeechRecognizer; //导入依赖的package包/类
@Override
public void onError(int error) {
    String text = "error" + error;
    switch (error) {
        case SpeechRecognizer.ERROR_NO_MATCH:
            text = "Je n'ai pas compris";
            break;
        case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
            if (isAwake) {
                text = "Essayez encore s'il vous plaît...";
            }
            break;
        case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:

    }
    try {
        speechRecognizer.stopListening();
        Thread.sleep(2000);
        speechRecognizer.startListening(intent);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    Log.d(TAG, text);
    textView.setText(text);
}
 
开发者ID:Palo-IT,项目名称:voice-IT,代码行数:26,代码来源:SpeechToTextAction.java


注:本文中的android.speech.SpeechRecognizer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。