2

プログラムで[今すぐ話す]ダイアログを開くことはできますか?

現在、ユーザーが[検索]ボタンをタップすると、ダイアログが開き、ソフトキーボードが自動的に開くので、ユーザーはテキストエディットフィールドをタップする必要がありません。

ダイアログを開き、[今すぐ話す]ウィンドウを自動的に開く代替の[音声で検索]を提供したいと思います。したがって、ユーザーはキーボードの「マイク」ボタンを見つけてタップする必要はありません。

何か案は?

4

1 に答える 1

4

はい、可能です。AndroidSDKのApiDemosサンプルをご覧ください。という名前のアクティビティがありVoiceRecognition、それを利用しRecognizerIntentます。

基本的に、あなたがする必要があるのは、いくつかの追加機能で適切な意図を作成し、結果を読むことだけです。

private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;

private void startVoiceRecognitionActivity() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    // identifying your application to the Google service
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
    // hint in the dialog
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
    // hint to the recognizer about what the user is going to say
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                    RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    // number of results
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
    // recognition language
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,"en-US");
    startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
        ArrayList<String> matches = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
        // do whatever you want with the results
    }
    super.onActivityResult(requestCode, resultCode, data);
}
于 2012-10-14T22:24:32.770 に答える