语音识别 - 获取支持的所有语言 - Android电子 [英] Speech Recognition - get all languages supported - Android

查看:624
本文介绍了语音识别 - 获取支持的所有语言 - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很难得到这个工作。我只是试图找出所有语音识别支持的可用语言,也是code使用它。

I'm having a hard time getting this to work. I'm just trying to find out all the available languages supported by speech recognition, and also the code to use it.

RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES

这应该汇报G上的讲话识别测试服务器上的所有可用语言作为一个数组。不幸的是我甚至无法把它吐出来的。我主要只是有与广播接收器,我认为问题。

Which should report back all available languages on G's speech recog servers as an array. Unfortunately I can't even get it to spit out one. I'm mainly just having problems with the BroadcastReceiver I think.

package com.thatll.ddo;

import java.util.ArrayList;
import java.util.logging.Logger;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.util.Log;
import android.widget.Toast;

public class RecogtestActivity extends Activity {
    private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;



/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Log.i("Log", "startVoiceRecognitionActivity");
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "speech recognition demo");

    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) {

     Intent intent = new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
     LangBroadcastReceiver myBroadcastReceiver = new LangBroadcastReceiver(this, data.getStringArrayListExtra(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES));
     sendOrderedBroadcast(intent, null, myBroadcastReceiver, null, Activity.RESULT_OK, null, null);

  } else {
     Toast.makeText(getApplicationContext(), "Voice recognition failed.", Toast.LENGTH_LONG).show();
  }
  super.onActivityResult(requestCode, resultCode, data);
}



/**
 * After a voice recognition is performed, need to sent a broadcast to
 * request the language used. This BroadcastReceiver gets the response and
 * then processes the original recognisedText from the
 * ACTION_RECOGNIZE_SPEECH Intent.
 * 
 */
public class LangBroadcastReceiver extends BroadcastReceiver {
  ArrayList<String> recognisedText;
  Activity parentActivity;

  /**
   * Store these for later use...
   * @param activity
   * @param arrayList
   */
  LangBroadcastReceiver(Activity activity, ArrayList<String> arrayList) {
     recognisedText = arrayList;
     parentActivity = activity;
  }

  @Override
  public void onReceive(Context context, Intent intent) {
     Bundle results = getResultExtras(true);
     String lang = results.getString(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);
     Log.d("log", "MyBroadcastReceiver: Got 'EXTRA_LANGUAGE_PREFERENCE' = " + lang);
     // now handle the recognisedText with the known language.

     ArrayList<CharSequence> hints = getResultExtras(true)
             .getCharSequenceArrayList(
                     RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);

     Log.d("log", "MyBroadcastReceiver: Got 'EXTRA_LANGUAGE_PREFERENCE' =   " + hints);

  }

}}

我想知道这是为什么不工作,但在这一点上我是一样高兴,如果我得到了目前支持的语言的完整列表。尝试了各种不同的方法和它的开始,现在烦扰我。

I'd like to know why this isn't working but at this point I'd be just as happy if I got the full list of currently supported languages. Tried various different methods and it's starting to annoy me now.

感谢您的帮助。

推荐答案

请在这里看到我的回答,我将介绍如何执行 RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS 正确的:

Please see my answer here, I describe how to execute RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS properly:

<一个href=\"http://stackoverflow.com/questions/10538791/how-to-set-the-language-in-speech-recognition-on-android/10548680#10548680\">How设置语音识别的语言在Android?

这篇关于语音识别 - 获取支持的所有语言 - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆