在Android的语音识别语音识别、Android

2023-09-04 03:17:38 作者:伊人莫相忘

我的工作在语音识别,需要一些示例程序。

I am working on speech recognition and need some sample programs.

任何人都可以指导我?

推荐答案

让我剪切和粘贴了一下,告诉你什么是code,你将需要。

Let me cut and paste a bit to show you what code you will need.

编辑:您还可以从this项目。

您将需要此意图(参数,你认为合适):

You will need this intent (parameterize as you see fit):

public Intent getRecognizeIntent(String promptToUse, int maxResultsToReturn)
{
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResultsToReturn);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, promptToUse);
    return intent;
}

然后,你需要你的意图发送到像这样的语音识别活动,

Then you need to send your intent to the speech recognition activity like so,

public void gatherSpeech(String prompt)
{
    Intent recognizeIntent = getRecognizeIntent(prompt);
    try
    {
        startActivityForResult(recognizeIntent, SpeechGatherer.VOICE_RECOGNITION_REQUEST_CODE);
    }
    catch (ActivityNotFoundException actNotFound)
    {
        Log.w(D_LOG, "did not find the speech activity, not doing it");
    }
}

然后,你将需要有你的活动处理的讲话结果:

Then you will need to have your activity handle the speech result:

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    Log.d("Speech", "GOT SPEECH RESULT " + resultCode + " req: "
        + requestCode);
    if (requestCode == SpeechGatherer.VOICE_RECOGNITION_REQUEST_CODE)
    {
        if (resultCode == RESULT_OK)
        {
            ArrayList<String> matches = data
                            .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            Log.d(D_LOG, "matches: ");
            for (String match : matches)
            {
                Log.d(D_LOG, match);
            }
        }
    }
}
 
精彩推荐
图片推荐