是否在Android的谷歌语音识别需要互联网?互联网、语音识别、Android

2023-09-06 16:13:38 作者:旧城俨然回眸笑ゝ

我用下面的code。通过谷歌来调用语音识别:

I use the following code to invoke the voice recognizer by 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);
    }


}  

这个工程没有在我的测试机的网络连接是的Nexus 7与Android 4.3。我认为这会工作一样在任何Android设备。然而,当我尝试在三星Galaxy S2采用Android版本gingerbread.el21,语音识别器的活动显示了,但是他说,这需要网络连接,并拒绝工作。为什么它的Nexus 7并没有在GALAXY S2工作?它是否脱机工作还是需要网络连接?它的工作原理在Nexus 7,甚至当我停止wifi的。

This works without network connection in my test machine which is Nexus 7 with Android 4.3. I thought it would work the same on any android device. However, when I try it on Samsung Galaxy S2 with Android version gingerbread.el21, the voice recogniser activity shows up, but says it needs network connection and refuses to work. Why does it work in Nexus 7 and not in Galaxy S2? Does it work offline or does it need network connection? It works in the Nexus 7 even when I stop the wifi.

推荐答案

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

In jellybean the user needs to download the offline speech recognition package.

这赛斯的文章:

previously,当你pressed的声音图标,并讲了命令或查询,机器人不得不数字化你的声音,把它上传到云端,处理波形,把它变成文字,并发送文本回落到您的手机。现在的手机都是足够的,这是可以内置在设备功能强大,没有I / O需要额外的网络。正如你可以想像这将导致更快的语音识别超过previous版本。

Previously, when you pressed the voice icon and spoke a command or query, Android had to digitize your voice, upload it to the cloud, process the waveform, turn it into text, and send the text back down to your phone. Now the phones are powerful enough that this can be built into the device, with no extra network I/O needed. As you can imagine this results in much faster voice recognition than previous versions.

该应用程序的用户将不得不这样做这个:

The app user will have to do this:

进入语言和输入法中的设置 在下面的语音下载离线语音识别点击 搜索 选择您希望您的Andr​​oid设备识别语言包 下载包,享受离线语音输入 Go to "Language and Input" in the Setting Tap on "Download offline speech recognition" under the "Voice Search" Choose the language pack you want your Android device to recognize Download the pack and enjoy the offline voice typing

另一个帮手链接:

谷歌已经从使用脱机承认,由于硬件限制,限制一定的果冻豆的设备。

Google have restricted certain Jelly Bean devices from using the offline recognition due to hardware constraints.