我已经学习了Android ApiDemos的示例代码,当我对着麦克风说话时,下面的代码可以使用谷歌语音搜索识别语音。
但是谷歌语音搜索有一些问题,谷歌语音搜索必须在线才能工作。
我已将语音保存到文件中,如何使用谷歌语音搜索来识别语音文件并返回结果?
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
// Fill the list view with the strings the recognizer thought it could have heard
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
matches));
}
super.onActivityResult(requestCode, resultCode, data);
}发布于 2013-08-19 03:54:04
除了使用提供的API在麦克风上运行之外,没有办法让Google语音识别器在任何东西上运行。同样,也没有使用底层web服务的官方方式,尽管有一种基于铬源代码的非官方方式。
如果要脱机进行语音识别,可以在设备上运行PocketSphinx。或者,您可以尝试查找可用于语音识别的在线API,但大多数主要API要么无法获得许可,要么非常昂贵。
https://stackoverflow.com/questions/18143210
复制相似问题