5

エミュレータで音声認識を使用してコードをテキスト化する方法を知りたいです。私のコードは実際のデバイスでは機能しますが、エミュレーターでは機能しません。エラーは言った:

 No Activity found to handle Intent { act=android.speech.action.RECOGNIZE_SPEECH (has extras) }

私に何ができる?

4

5 に答える 5

8
package net.viralpatel.android.speechtotextdemo;

import java.util.ArrayList;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

    protected static final int RESULT_SPEECH = 1;

    private ImageButton btnSpeak;
    private TextView txtText;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txtText = (TextView) findViewById(R.id.txtText);

        btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);

        btnSpeak.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent intent = new Intent(
                        RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

                try {
                    startActivityForResult(intent, RESULT_SPEECH);
                    txtText.setText("");
                } catch (ActivityNotFoundException a) {
                    Toast t = Toast.makeText(getApplicationContext(),
                            "Ops! Your device doesn't support Speech to Text",
                            Toast.LENGTH_SHORT);
                    t.show();
                }
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @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);

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

        }
    }
}
于 2012-10-20T14:14:52.460 に答える
1

RECOGNIZE_SPEECH-intentを処理するアクティビティを含むアプリをエミュレーターにインストールする必要があります。VoiceSearch.apkあなたはウェブ上でグーグルを見つけることができるかもしれません。

于 2011-12-19T13:33:01.587 に答える
0

エミュレーターを使用してテストできないことがいくつかあります。テキストへのスピーチはそれらの上にあります。

これについてはよくわかりませんが、エミュレータでこのAndroid機能を使用することはできません。

いずれにせよ、この例外をtry / catchで処理して、ユーザーにフィードバックを与える必要があります。

Activityアプリを実行している現在のデバイスに次のようなことを行っているかどうかを確認できます。

        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> infoList = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
        if (infoList.size() == 0) {
             /** Show some feedback to user if there is the activity. Something like "Your device is not abl to run this feature..."*/
        }else{
             /**Your current code goes here.*/
        }

それが役立つかどうか教えてください。

于 2012-10-21T22:48:45.887 に答える
0

com.google.android.voicesearch次のような音声認識アクティビティがないターゲットデバイスにアプリケーションをインストールする必要があります。

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.voicesearch"));
startActivity(browserIntent);

Googleの検索アプリをインストールしようとすると(内部にVRエンジンが含まれていないため、同じようにインストールしようとしますがcom.google.android.voicesearch、パッケージ名のバグが原因で失敗する可能性があります)、役に立ちませpname:com.google.android.voicesearchん。純粋なパッケージ名)。ただしcom.google.android.voicesearch、「お住まいの国ではご利用いただけません」などの理由でインストールできない場合があります。

于 2014-06-14T09:47:24.703 に答える
-3

仮想SDカードが必要になる場合があります。ここで参照できます

于 2011-12-17T07:17:33.773 に答える