- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
Android Dev 网站提供了一个使用内置 Google Speech Input Activity 进行语音输入的示例。该 Activity 显示一个带有麦克风的预配置弹出窗口,并使用 onActivityResult()
我的问题:有没有办法直接使用 SpeechRecognizer
类进行语音输入而不显示预设 Activity ?这将让我为语音输入构建自己的 Activity 。
最佳答案
这是使用 SpeechRecognizer 类的代码(来自 here 和 here ):
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import android.util.Log;
public class VoiceRecognitionTest extends Activity implements OnClickListener
{
private TextView mText;
private SpeechRecognizer sr;
private static final String TAG = "MyStt3Activity";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button speakButton = (Button) findViewById(R.id.btn_speak);
mText = (TextView) findViewById(R.id.textView1);
speakButton.setOnClickListener(this);
sr = SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(new listener());
}
class listener implements RecognitionListener
{
public void onReadyForSpeech(Bundle params)
{
Log.d(TAG, "onReadyForSpeech");
}
public void onBeginningOfSpeech()
{
Log.d(TAG, "onBeginningOfSpeech");
}
public void onRmsChanged(float rmsdB)
{
Log.d(TAG, "onRmsChanged");
}
public void onBufferReceived(byte[] buffer)
{
Log.d(TAG, "onBufferReceived");
}
public void onEndOfSpeech()
{
Log.d(TAG, "onEndofSpeech");
}
public void onError(int error)
{
Log.d(TAG, "error " + error);
mText.setText("error " + error);
}
public void onResults(Bundle results)
{
String str = new String();
Log.d(TAG, "onResults " + results);
ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
for (int i = 0; i < data.size(); i++)
{
Log.d(TAG, "result " + data.get(i));
str += data.get(i);
}
mText.setText("results: "+String.valueOf(data.size()));
}
public void onPartialResults(Bundle partialResults)
{
Log.d(TAG, "onPartialResults");
}
public void onEvent(int eventType, Bundle params)
{
Log.d(TAG, "onEvent " + eventType);
}
}
public void onClick(View v) {
if (v.getId() == R.id.btn_speak)
{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5);
sr.startListening(intent);
Log.i("111111","11111111");
}
}
}
使用按钮定义 main.xml 并在 list 中授予 RECORD_AUDIO 权限
关于android - 有没有办法直接使用 SpeechRecognizer API 进行语音输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4975443/
SpeechRecognizer 正常工作了很长时间,突然它不工作了,现在没有检测到任何东西.. 示例代码是这样的。当它在线时它可以正常工作但离线时不能,我错过了吗什么地方都有??? Spee
我正在尝试在没有 Intent Dialog 的情况下在 Android 上使用 SpeechRecognizer。它在大多数设备上都可以正常工作,但有些设备会返回音频录制错误(错误代码 3)并且没有
我正在编写WinRT应用,并在VS 2015,x86调试中对其进行测试。我正进入(状态 我的应用程序未创建不需要的音频输出。这是我的代码: using Windows.Media.SpeechReco
我在 Activity 中使用 Native SpeechRecognizer 服务,它“有效”,但我遇到了一些严重的问题。 返回的“语音转文本”坦率地说非常令人震惊,而且非常非常差,在应用程序中肯定
简介 我需要在我的代码中实现语音识别。我按照这里的其他帖子和一些教程来获取它,但它不适合我。 方法 这是在 onCreate 中初始化它的代码: Log.d("SPEECH", "speech rec
我遇到一个问题,SpeechRecognizer 将正确收听,当我下次收听它时转到 SpeechRecognizer.ERROR_NO_MATCH,识别器立即无法 SpeechRecognizer.E
我知道 SpeechRecognizer 在 android 中是如何工作的。我有一个要求,我需要在一段时间后调用 SpeechRecognizer.stopListening() 方法。但在那之后,
我正在学习有关 iOS 10 语音识别 API 的一些教程 (https://code.tutsplus.com/tutorials/using-the-speech-recognition-api-
我正在使用 SppechRecognizer用于语音识别器应用程序。它工作正常。我的要求是我想在 1 秒或 2 秒后停止收听语音。如何实现? 最佳答案 1 或 2 秒似乎不是很多时间,但如果你想设置一
有没有办法在通话时运行 SpeechRecognizer?我是这样做的: BroadcastReceiver 处理电话状态的变化(例如摘机)。 SpeechRecognizer 在当前(主)线程中启动
我正在尝试在我的 Android 应用程序中使用 SpeechRecognizer 库,到目前为止,它的工作给我留下了很多问题。首先,当我停止说话时它不会停止。如果我试图停止语音识别自己,下次它会给我
如何找到默认系统语音识别器的 ComponentName,即 createSpeechRecognizer(Context context) 时返回的那个叫做? (其实我只需要知道它支持哪些输入语言,
我正在尝试在 Android 4.4 中创建连续语音识别,简单地在 TextView 中显示口语,就像命令一样。我遵循了多个教程,例如 https://github.com/fcrisciani/an
我在 Android 中使用 SpeechRecognizer 和 RecognizerIntent 来实现语音识别。我的目标是在我的语音识别器在屏幕上显示结果后重新开始收听语音。为此,我使用了以下代
我正在使用名为 SpeechRecognizer 的 Android 语音 API 尝试将语音翻译成文本,但由于某种原因,只要我点击按钮 - 我就会看到消息 “目前无法访问谷歌” ,不等我讲话, wi
我使用 SpeechRecognizer 来实现“语音到文本”功能,她的工作结果是文本数据: Intent intent = new Intent(RecognizerIntent.ACTION_RE
我有一个 maind UI 类,其中有一个按钮实例化一个类,该类正在实现 SpeechRecognizer 库以将语音从文本转换为文本。 btnSpeak = (ImageButton) findVi
我有一个相当奇怪的问题。我有一个 Android 应用程序,我使用 SpeechRecognizer 类为其添加语音识别。我创建了实现 RecognitionListener 的类,它只打印每个事件的
我正在开发 UWP 并想使用 SpeechRecognizer。它应该只对“Next”和“Back”这两个词使用react。但通常,它会将“NExt”识别为“Back”。我的代码如下。如何解决? va
请看下面的代码。 onBeginningOfSpeech() 被调用(甚至在我开始说话之前,顺便说一句),但随后 - 没有。我错过了什么? 我承认代码大部分是由不同的例子组成的,我没有完全理解。但我希
我是一名优秀的程序员,十分优秀!