本文介绍了声音在离线模式在Android文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反正是有,我可以使用语音到文本的Andr​​oid功能在离线模式下。

Is there anyway in which I can use the Voice to Text feature of Android in offline mode.

在给定的例子VoiceRecognition.java,它开始​​和活动的意图RecognizerIntent.ACTION_RECOGNIZE_SPEECH

In the given example VoiceRecognition.java, it starts and activity with the intent RecognizerIntent.ACTION_RECOGNIZE_SPEECH.

这是否意味着其他任何需要的apk前手要安装这个工作还是我需要写我自己的应用程序启动这个意图。

Does it mean that any other apk needs to be installed before hand for this to work or do I need to write my own application to launch on this intent.

我一直在寻找这很长一段时间,但越来越困惑...

I have been searching for this for a long time but is getting confused...

下面是code我用..

Here is the code I used..

private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;

private ListView mList;

/**
 * Called with the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Inflate our UI from its XML layout description.
    setContentView(R.layout.voice_recognition);

    // Get display items for later interaction
    Button speakButton = (Button) findViewById(R.id.btn_speak);

    mList = (ListView) findViewById(R.id.list);

    // Check to see if a recognition activity is present
    PackageManager pm = getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(
            new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (activities.size() != 0) {
        speakButton.setOnClickListener(this);
    } else {
        speakButton.setEnabled(false);
        speakButton.setText("Recognizer not present");
    }
}

/**
 * Handle the click on the start recognition button.
 */
public void onClick(View v) {
    if (v.getId() == R.id.btn_speak) {
        startVoiceRecognitionActivity();
    }
}

/**
 * Fire an intent to start the speech recognition activity.
 */
private void startVoiceRecognitionActivity() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
    startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}

/**
 * Handle the results from the recognition activity.
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
        // Fill the list view with the strings the recognizer thought it could have heard
        ArrayList<String> matches = data.getStringArrayListExtra(
                RecognizerIntent.EXTRA_RESULTS);
        mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                matches));
    }

    super.onActivityResult(requestCode, resultCode, data);
}

在运行此code它给识别器不是present这意味着没有这样的活动是present。如何解决此问题?

On running this code it gives Recognizer not present which means no such activity is present. How to resolve this?

推荐答案

我觉得你有两个问题。首先,是识别器的功能并不适用于所有设备。请确保您安装并更新最新的谷歌语音搜索为Android。我相信它会安装最新的识别。请参见 http://www.google.com/mobile/voice-actions/ 可能会有所帮助。

I think you have two problems. First, yes the recognizer functionality is not available on all devices. Make sure you install and update the latest Google Voice Search for Android. I believe it installs the latest recognizer. See http://www.google.com/mobile/voice-actions/ it may be helpful.

正如但丁江表示将语音转换为文本,根据的,的是你真正需要的。

As Dante Jiang said in Converting speech to text, According to this article, Google Voice Search is what you actually need.

Android的SDK可以很容易地  集成语音输入直接进入  自己的应用程序,只需复制并  从这个示例应用程序粘贴  上手。 Android是一个开放  平台,使应用程序可以  有可能利用任何言论  在设备上识别服务  该公司注册接收  RecognizerIntent。谷歌的语音  搜索应用程序,这是  pre-安装在许多Android设备,  响应一个RecognizerIntent由  显示现在讲对话框,  流式音频到谷歌的  服务器,所用的相同的服务器时,  用户点击的麦克风按钮  搜索Widget或语音功能  键盘。 (你可以,如果检查语音  搜索是安装在设置➝  应用➝管理应用程序。)

在code,你应该检查,看看是否认识活动是present。我有下面的代码片段我用:

In code, you should check to see if the recognition activity is present. I have the following snippet I've used:

// Check to see if a recognition activity is present
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(
        new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() != 0) 
{
    speakButton.setOnClickListener(this);
} 
else 
{
    speakButton.setEnabled(false);
    speakButton.setText(R.string.recognizer_not_present);
}

第二个问题是,Android的语音识别需要互联网连接。是不是在设备上执行的认可,而是使用谷歌网络服务。所以,你必须在线。对Web服务的一些信息,请访问http://waxy.org/2008/11/deconstructing_google_mobiles_voice_search_on_the_iphone/.

这篇关于声音在离线模式在Android文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 12:17