- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试在我的 Android 应用程序中使用 SpeechRecognizer 库,到目前为止,它的工作给我留下了很多问题。首先,当我停止说话时它不会停止。如果我试图停止语音识别自己,下次它会给我“不匹配!”马上。
我的问题是:当我使用谷歌语音识别时(例如,当我在网络上搜索时),它就像一个魅力。在我的应用程序中,它远非完美,尽管库是一样的。我的实现有什么问题?
我的代码(简化版):
注意:我尝试使用部分结果来使语音识别更加灵活,但除了识别速度变快之外,我看不到任何效果。
public void setupVoiceRecognition(Activity activity) {
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(activity.getApplicationContext());
mSpeechRecognizer.setRecognitionListener(this);
mRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
activity.getPackageName());
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,
true);
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mRecognizerIntent.putExtra(EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 5000);
mRecognizerIntent.putExtra(EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 3000);
mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
mContext = activity.getApplicationContext();
if (mMainBtn != null) {
mMainBtn.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
VoiceRecognition.this.onClick();
}
});
}
}
public void forceStop() {
if (mListening) {
toggleListening(false);
}
}
public void onClick() {
toggleListening(!mListening);
}
private void toggleListening(boolean start) {
mPartialLength = 0;
if (start) {
mSpeechRecognizer.startListening(mRecognizerIntent);
} else {
mSpeechRecognizer.stopListening();
}
if (mMainBtn != null) {
mMainBtn.setImageResource((start) ? R.drawable.icon_record_active : R.drawable.icon_record_white);
}
if (mSupportBtn != null) {
mSupportBtn.setImageResource((start) ? R.drawable.icon_record_active : R.drawable.icon_record_white);
}
mListening = start;
}
...
@Override public void onError(int i) {
if (mListening) {
String errorText;
switch (i) {
case SpeechRecognizer.ERROR_AUDIO:
errorText = MyApp.getContext().getString(R.string.speech_recognition_err3);
break;
...
}
MyApp.showToast(errorText);
toggleListening(false);
if (i == NO_MATCH) {
toggleListening(true);
}
}
}
@Override public void onResults(Bundle bundle) {
ArrayList<String> matches = bundle
.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if (matches != null) {
String fullText = mViewForText.getText().toString();
mViewForText.setText(fullText.substring(0, fullText.length() - mPartialLength) + matches.get(0) + " ");
mViewForText.requestFocus(View.FOCUS_RIGHT);
mViewForText.setSelection(mViewForText.getText().length());
mPartialLength = 0;
forceStop();
}
}
@Override public void onPartialResults(Bundle bundle) {
ArrayList<String> matches = bundle
.getStringArrayList(EXTRA_PARTIAL_RESULTS);
if (matches != null) {
mViewForText.setText(mViewForText.getText().toString() + matches.get(0) + " ");
mPartialLength += matches.get(0).length() + 1;
mViewForText.requestFocus(View.FOCUS_RIGHT);
mViewForText.setSelection(mViewForText.getText().length());
}
}
}
最佳答案
Google 通过第三方应用程序的 SpeechRecognizer 禁用了连续语音识别。我认为这是因为他们现在已经付费 API ( https://cloud.google.com/speech/ ),它运行良好但不是免费的。
关于 NO_MATCH 错误。谷歌听到自己的哔哔声邀请信号并假定这是演讲开始。如无法识别提示音则返回NO_MATCH错误。
有一个选项。您可以降级 Google 应用程序以获得更稳定的识别服务工作。 Google 应用程序的最后一个正常工作版本是 6.2.34
关于java - SpeechRecognizer 在启动后立即不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47695367/
我希望在我的应用程序下载信息时显示 Toast 消息,但即使我将它放在我的代码之前,它也不会在下载完成后出现。将我的代码放在一个单独的线程中会引起很多麻烦,但是将 toast 放在一个单独的线程中也不
面临即时应用更新模式的问题。成功完成应用程序更新后,一切都关闭并且不重新启动应用程序。这就是问题所在。 但是android文档说: A full screen user experience that
我有一张 table 我有一个 anchor 标记,
我正在开发一个具有两个线程的 Java/Seam/Hibernate/Glassfish 应用程序: 线程 #1 发送各种消息并将摘要信息写入 MySQL 数据库。 线程 #2 定期轮询数据库(由 S
我找不到规范的相关部分来回答这个问题。在 Java 中的条件运算符语句中,是否同时评估真假参数? 以下是否会抛出 NullPointerException Integer test = null; t
大家下午好, 我想知道是否有办法使类的静态 block 运行,即使类本身没有被引用? 我知道它是延迟加载的,因此只需调用该类的任何函数即可开始启动该类, 但是,我希望该类在任何调用之前启动,换句话说,
我正在尝试使用 jQuery prop() 方法禁用元素(表单字段)。有两个字段,一个叫做fee,一个叫做currency。每当 fee 设置为 0 时,第二个字段 currency 将被禁用。这样做
我想为 UIButton 的缩放设置动画,并在完成后再次为缩放设置动画,但让它在没有动画的情况下旋转。我尝试将旋转变换放在没有持续时间的动画调用中,但不知何故它仍然成为缩放动画的一部分或替换缩放动画。
在 js 代码中,我创建了 3 个按钮 --- 按钮 1...按钮 2...按钮 3和 3 个输入字段 --- 输入字段 1...输入字段 2...输入字段 3 从脚本开始所有按钮都被禁用 只有当输入
我正在使用一个 threading.Thread() 来完成它的工作并返回 。它的返回记录在打印语句中,所以我确信有时候是这样的。然而,依靠 threading.active_count() 和 th
我正在使用 IntelliJ 9,我很好奇是否有任何与 Visual Studio“即时”调试窗口等效的 IntelliJ。在编辑器中选择所需的表达式,然后 ALT-F8 来评估表达式,但我希望能够在
我有一个两个标签页,一个标签是记录列表,点击记录会切换到编辑标签,编辑标签中有保存和取消按钮。 现在,我单击记录 #1,进行一些编辑,然后单击取消按钮。当然我不想验证表单,因为它被取消了,所以我设置了
我有一个 A viewController,首先,我呈现 B viewController,经过一些工作后,我需要关闭 B viewController 并呈现 C viewController,所以
我希望能够在文本框中输入内容,当用户在文本框中输入内容时,我希望程序无需单击按钮即可自动读取文本框。 例子:用户类型:“abcd”当用户输入时,程序会显示每个字母对应的数字。 程序输出:“1234”
如果任何表单输入发生更改,如何立即更改提交按钮文本? //This applies to whole form $('#test').change(function() { $("#send").
主要功能: var interval; function refreshId(sessio
假设我有一个包含这些列的 data.table nodeID hour1aaa hour1bbb hour1ccc hour2aaa hour2bbb hour2ccc .
根据vimeo js-api doc ,事件 finish - 当视频播放结束时触发。 出于某种原因,我无法让它工作,finish 事件总是立即调用,我做错了什么吗? 我试图让嵌入的视频在播放完毕后消
我想滑动当前ul元素下的所有li元素和slideDown li元素 $(document).ready(function(){ $("li").slideUp(); }); $(".nav")
我有一个表-compositeView,其中有行-itemView。每行都有许多事件 - 单击、更改等等。 在某些状态下,我想“锁定”表。禁用按钮并取消事件。 是否有一种好方法可以立即取消 itemv
我是一名优秀的程序员,十分优秀!