【发布时间】:2016-06-16 10:47:40
【问题描述】:
SpeechRecognizer 在带有 Google Apps (GApps) 的 Android 上运行良好。但是在中国,大多数 Android 设备都会删除这些 Google Apps。使用SpeechRecognizer 会发生什么?没有实际设备我怎么能测试它?
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
speechRecognizer.setRecognitionListener(new CustomListener());
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "zh_HK");
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, false);
intent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", new String[]{"zh_HK", "en-US"});
speechRecognizer.startListening(intent);
CustomListener() 在哪里实现RecognitionListener。
【问题讨论】:
-
一种可能性是通过 PackageManager 检查是否安装了
Gapps,例如检查com.android.vending。如果没有,那么语音识别的另一种方法可能是 sphinx:cmusphinx.sourceforge.net -
好主意。但是,Sphinx 的语言文件占用了很多空间。如果不添加检查,上面的代码会崩溃吗?
-
嗯,这是一个很好的问题,如果可以的话,我会对此给予更多的支持。但真的......我不知道。如果我从正常情况开始,如果没有包来执行此操作,则处理某些操作的 Intent 将崩溃。我认为缺少gapps也是一样,为什么要以另一种方式处理。避免这种情况可以通过 intent.resolveActivity(pckManager) != null` 来完成,我猜。
-
如果您有一些未使用的设备并安装 cyanogenmod 没有间隙,也许您可以测试它。
-
另一个想法是使用
com.android.vending将<uses-feature>设置为清单,但我从未尝试为软件提供使用功能。但它在 API 中有描述,for hardware or software......
标签: android speech-recognition