在Android4.1中,你可以使用keyboard上的麦克风选项进行实时语音到文本的转换。
我一直在看android.speech的文档,试图找出如何为应用程序实现实时语音到文本。但是,唯一可以促进这一点的选项是"EXTRA_PARTIAL_RESULTS“选项(每次我尝试使用它时,服务器都会忽略它)。
代码:
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, "VoiceIME");
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 3000L);
mSpeaker.startListening(intent);从不返回部分结果。
我知道这是可能的,因为键盘版本一直是这样做的。有人知道怎么做吗?
发布于 2012-12-24 20:05:14
在调用startListening之前,您需要注册onPartialResults-callback。需要注意的两件重要事情:
onPartialResults所使用的包的结构不是由Android API指定的;因此您的代码将特定于Google Voice Search。
mSpeaker.setRecognitionListener(new RecognitionListener() {
...
public void onPartialResults(Bundle partialResults) {
// WARNING: The following is specific to Google Voice Search
String[] results =
partialResults.getStringArray("com.google.android.voicesearch.UNSUPPORTED_PARTIAL_RESULTS");
updateTheUi(results);
}
...
}要在开源应用程序中查看此回调的实际效果,请参阅Babble:
谷歌Play:https://play.google.com/store/apps/details?id=be.lukin.android.babble
发布于 2013-02-19 23:57:54
如果你想在麦克风打开时实时显示部分结果,而扬声器正在说话,你可能想放弃使用recognizerIntent的方法,而放弃recognitionService,转而使用简单的安卓文本框并预先选择“麦克风”图标,就像你可以在安卓笔记的示例应用程序中所做的那样……
请参阅./samples/android-16/NotePad/tests/src/com/example/android/notepad
这个组合提供了这样的功能:当语音合成结果从服务器端的“voiceSearch”返回时,你可以实时看到它们,这在某种程度上与“识别器”关于“部分”回调的不同。
大量评论指出,recognizerIntent不会触发对“onPartialResults”的回调。出于某些原因,Android4.2似乎不支持“连续”speechRecognition模式,而这种模式使用javascript运行得很好。我在4.2上对“RecognitionListener”接口的测试显示,在卷事件上有数百个对“onRmsChanged”的回调,但在“partialResult”事件上没有任何活动。在某个地方,这个回调丢失了??
对于js解决方案,请安装chrome-beta版本25并执行here
使用android笔记应用程序。从键盘上采样并预先选择麦克风图标,您可以执行与上面的JS webapp链接完全相同的操作。
发布于 2016-07-13 21:02:08
因为我们不能确切地知道来自部分结果回调的Bundle的键名,所以使用下面的代码来查找它的内容:
public void onPartialResults(Bundle partialResults) {
String string = "Bundle{";
for (String key : partialResults.keySet()) {
string += " " + key + " => " + partialResults.get(key) + ";";
}
Log.e("joshtag","onPartialResults"+string);
//see the keynames in Logcat and extract partial reesults here
}https://stackoverflow.com/questions/14000275
复制相似问题