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


Java RecognizerIntent類代碼示例

本文整理匯總了Java中android.speech.RecognizerIntent的典型用法代碼示例。如果您正苦於以下問題:Java RecognizerIntent類的具體用法?Java RecognizerIntent怎麽用?Java RecognizerIntent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RecognizerIntent類屬於android.speech包,在下文中一共展示了RecognizerIntent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: SpeechRecognizerManager

import android.speech.RecognizerIntent; //導入依賴的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.RecognizerIntent; //導入依賴的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: onActivityResult

import android.speech.RecognizerIntent; //導入依賴的package包/類
/**
 * Receiving speech input
 * */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
        case REQ_CODE_SPEECH_INPUT: {
            if (resultCode == RESULT_OK && null != data) {

                ArrayList<String> result = data
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                txtSpeechInput.setText(result.get(0));
            }
            break;
        }

    }
}
 
開發者ID:Captwalloper,項目名稱:NUI_Project,代碼行數:21,代碼來源:VoiceActivity.java

示例4: onActivityResult

import android.speech.RecognizerIntent; //導入依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case RESULT_SPEECH: {
            if (resultCode == RESULT_OK && null != data) {

                ArrayList<String> text = data
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

                autoCompleteTextView.setText(text.get(0));
            }
            break;
        }

    }
}
 
開發者ID:Mun0n,項目名稱:MADBike,代碼行數:18,代碼來源:SearchActivity.java

示例5: StudentAdapterViewHolder

import android.speech.RecognizerIntent; //導入依賴的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

示例6: onActivityResult

import android.speech.RecognizerIntent; //導入依賴的package包/類
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == Activity.RESULT_OK)
    {
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        if (matches != null && matches.size() > 0)
        {
            String searchWrd = matches.get(0);
            if (!TextUtils.isEmpty(searchWrd))
            {
                mSearchView.setQuery(searchWrd, false);
            }
        }
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
開發者ID:WeDevelopTeam,項目名稱:HeroVideo-master,代碼行數:19,代碼來源:HomePageFragment.java

示例7: startVoiceRecognition

import android.speech.RecognizerIntent; //導入依賴的package包/類
void startVoiceRecognition() {
    try{
        //通過Intent傳遞語音識別的模式,開啟語音
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        //語言模式和自由模式的語音識別
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        //提示語音開始
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "開始語音");
        //開始語音識別
        startActivityForResult(intent, VOICE_SEARCH_CODE);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), "找不到語音設備", 1).show();
    }
}
 
開發者ID:aliyun,項目名稱:aliyun-cloudphotos-android-demo,代碼行數:17,代碼來源:MainActivity.java

示例8: retrieveInputFromUser

import android.speech.RecognizerIntent; //導入依賴的package包/類
@Override
public void retrieveInputFromUser(Fragment fragment) {
    ensurePermission(fragment);

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            fragment.getString(R.string.speech_prompt));
    try {
        fragment.startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        setFailureMessage(fragment.getString(R.string.speech_not_supported));
    }
}
 
開發者ID:Captwalloper,項目名稱:NUI_Project,代碼行數:17,代碼來源:VoiceListener.java

示例9: getResult

import android.speech.RecognizerIntent; //導入依賴的package包/類
public VoiceResult getResult(int resultCode, Intent data) {
    if (hasFailureMessage()) {
        String message = popErrorMessage();
        return new VoiceResult(false, message);
    }
    else if (resultCode == RESULT_OK && null != data) {
        ArrayList<String> result = data
                .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        String value = result.get(0);
        return new VoiceResult(true, value);
    }
    else {
        throw new RuntimeException("VoiceListener failed to return an expected result.");
    }
}
 
開發者ID:Captwalloper,項目名稱:NUI_Project,代碼行數:16,代碼來源:VoiceListener.java

示例10: promptSpeechInput

import android.speech.RecognizerIntent; //導入依賴的package包/類
/**
 * Showing google speech input dialog
 * */
private void promptSpeechInput() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}
 
開發者ID:Captwalloper,項目名稱:NUI_Project,代碼行數:19,代碼來源:VoiceActivity.java

示例11: retrievePotentialMedicineNameFromVoiceRecognizedData

import android.speech.RecognizerIntent; //導入依賴的package包/類
private String retrievePotentialMedicineNameFromVoiceRecognizedData(Intent data) {
    List<String> voiceRecognizedData = data
            .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

    String potentialMedicineName = voiceRecognizedData.get(0);
    return potentialMedicineName;
}
 
開發者ID:lmnpWmi,項目名稱:wirtualnaApteczka,代碼行數:8,代碼來源:AddMedicineActivity.java

示例12: onClick

import android.speech.RecognizerIntent; //導入依賴的package包/類
@Override
public void onClick(View v) {
    Context context = v.getContext();

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            context.getString(R.string.speech_prompt));
    try {
        boolean isExecutedFromAddMedicine = context instanceof AddMedicineActivity;
        boolean isExecutedFromMedicineList = context instanceof MedicineListActivity;

        if (isExecutedFromAddMedicine) {
            ((AddMedicineActivity) context).startActivityForResult(intent, requestCode);
        }
        else if (isExecutedFromMedicineList) {
            ((MedicineListActivity) context).startActivityForResult(intent, requestCode);
        }
    } catch (ActivityNotFoundException a) {
        Toast.makeText(context,
                context.getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}
 
開發者ID:lmnpWmi,項目名稱:wirtualnaApteczka,代碼行數:27,代碼來源:LaunchVoiceRecognitionOnClickListener.java

示例13: onAutoPressed

import android.speech.RecognizerIntent; //導入依賴的package包/類
@OnClick(R.id.autoButton)
public void onAutoPressed() {
    if (clear) {
        autoCompleteTextView.setText("");
    } else {
        Intent intent = new Intent(
                RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, Locale.getDefault().getDisplayLanguage());

        try {
            startActivityForResult(intent, RESULT_SPEECH);
            autoCompleteTextView.setText("");
        } catch (ActivityNotFoundException a) {
            notificationManager.showMessage(getString(R.string.error_no_mic));
        }
    }
}
 
開發者ID:Mun0n,項目名稱:MADBike,代碼行數:19,代碼來源:SearchActivity.java

示例14: onActivityResult

import android.speech.RecognizerIntent; //導入依賴的package包/類
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

  if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == Activity.RESULT_OK) {
    ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    if (matches != null && matches.size() > 0) {
      String searchWrd = matches.get(0);
      if (!TextUtils.isEmpty(searchWrd)) {
        mSearchView.setQuery(searchWrd, false);
      }
    }

    return;
  }
  super.onActivityResult(requestCode, resultCode, data);
}
 
開發者ID:MUFCRyan,項目名稱:BilibiliClient,代碼行數:17,代碼來源:HomePageFragment.java

示例15: onSpeakButtonClick

import android.speech.RecognizerIntent; //導入依賴的package包/類
@OnClick(R.id.btnSpeak)
public void onSpeakButtonClick() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}
 
開發者ID:vixir,項目名稱:Perfect-Day,代碼行數:17,代碼來源:CreateTaskBySpeech.java


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