2

I have learned the sample code of Android ApiDemos, the following code can recognise voice using Google voice search when I speak to microphone.

But there are some problems with Google voice search, Google voice search must be online to work.

I have saved my voice to a file, how can I make Google voice search to recognise the voice file and return result?

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);
}
4

1 回答 1

1

除了使用提供的 API 的麦克风之外,无法让 Google 语音识别器在任何设备上运行。同样,也没有官方的方式来使用底层的 Web 服务,尽管有一种基于 chromium 源代码的非官方方式。

如果你想离线做语音识别,你可以在设备上运行PocketSphinx。或者,您可以尝试查找可用于语音识别的在线 API,但大多数主要 API 要么无法获得许可,要么非常昂贵。

于 2013-08-18T19:54:04.053 回答