【问题标题】:Does the Google speech recognizer on Android need internet?Android 上的 Google 语音识别器需要互联网吗?
【发布时间】:2013-10-24 11:22:23
【问题描述】:

我使用以下代码调用google的语音识别器:

// This is a demonstration of Android's built in speech recognizer

package com.example.voiceinputbuiltintest;

import java.util.ArrayList;
import java.util.Locale;

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

public class MainActivity extends Activity {

    private static final int VOICE_RECOGNITION = 1;
    Button speakButton ;
    TextView spokenWords; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        speakButton = (Button) findViewById(R.id.button1);  
        spokenWords = (TextView)findViewById(R.id.textView1);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    protected void onActivityResult(int requestCode,
            int resultCode,
            Intent data) {
        if (requestCode == VOICE_RECOGNITION && resultCode == RESULT_OK) {
            ArrayList<String> results;
            results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            // TODO Do something with the recognized voice strings

            Toast.makeText(this, results.get(0), Toast.LENGTH_SHORT).show();
            spokenWords.setText(results.get(0));
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    public void btnSpeak(View view){
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        // Specify free form input
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
        RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT,"Please start speaking");
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.ENGLISH);
        startActivityForResult(intent, VOICE_RECOGNITION);
    }


}  

这在我的测试机器上没有网络连接,它是带有 Android 4.3 的 Nexus 7。我认为它在任何 android 设备上都可以正常工作。然而,当我在三星 Galaxy S2 上使用 Android 版本的gingerbread.el21 试用它时,语音识别器活动出现了,但说它需要网络连接并拒绝工作。为什么它在 Nexus 7 中有效,而在 Galaxy S2 中无效?它是离线工作还是需要网络连接?即使我停止 wifi,它也可以在 Nexus 7 中使用。

【问题讨论】:

  • 那么更高版本的 Android 实际上确实具有离线执行此操作所需的文件?是否对此有任何确认,以及从哪个版本可用的信息?
  • @poutrathor 请看这个:stackoverflow.com/questions/17616994/…
  • 是的!我通过谷歌搜索离线语音识别来阅读更多内容,然后感谢@Dyna。我应该尝试回答更多问题,我正在学习东西:D
  • 我学到了很多回答问题的东西;)你帮助别人的同时也帮助了自己!
  • 嗨,帮我解决这个问题stackoverflow.com/questions/32866239/…

标签: android voice-recognition


【解决方案1】:

在 jellybean 中,用户需要下载离线语音识别包。

This文章sais:

以前,当您按下语音图标并说出命令或查询时,Android 必须将您的声音数字化,将其上传到云端,处理波形,将其转换为文本,然后将文本发送回您的手机。现在电话功能足够强大,可以将其内置到设备中,无需额外的网络 I/O。正如您可以想象的那样,这会导致语音识别速度比以前的版本快得多。

应用用户必须这样做this

  1. 进入设置中的“语言和输入法”
  2. 点击“语音”下的“下载离线语音识别” 搜索”
  3. 选择您希望 Android 设备识别的语言包
  4. 下载包,享受离线语音输入

另一个帮手link

由于硬件限制,Google 已限制某些 Jelly Bean 设备使用离线识别功能。

【讨论】:

  • 感谢您的快速回复。所以这个功能确实可以离线使用,而且它在 Nexus 7 中也可以使用,因为我已经更新了 Android 版本?
  • 顺便说一句,我从未明确下载过离线语音识别文件,但我确实将操作系统更新到了最新版本的 Android。我认为完成后离线语音识别也会自动下载
  • 是的,新版本可以离线使用,但我很确定你的 Galaxy s2 只有软糖豆,并且不允许你离线使用。
  • Galaxy S2 是 Gingerbread,所以我猜它没有这个功能
  • 顺便说一句,我发现了这个:stackoverflow.com/questions/17616994/… 这解释了为什么我无法找到有关此功能的大量信息。我想我很幸运 Nexus 7 恰好有足够的硬件规格能够离线运行此功能
猜你喜欢
  • 1970-01-01
  • 2013-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
  • 1970-01-01
  • 2015-09-04
  • 1970-01-01
相关资源
最近更新 更多