Java开源语音识别软件

9
我最近考虑开发一个基于语音识别的应用程序,即根据某些结果执行特定任务。我想知道最好的方法是什么。我正在考虑PC或Android平台。我会把JAVA作为我的主要编程语言。
我已经搜索过一些资料,但仍然不知道最佳方法是什么。
一种方法是使用开源软件完成语音识别部分,而我负责其他部分。另一种方法是自己完成整个项目。如果是后者,使用JAVA是否可行?
非常感谢您提供的任何信息。
3个回答

6

最好的方法是使用现有的语音识别工具包以及附带的语言和声学模型。您可以训练这些模型来适应您的需求。

CMUSphinx 可能是目前最好的自由软件语音识别工具包。CMUSphinx 还提供了良好的 Java 集成和演示应用程序。


这不是我第一次听说CMUSphinx,当时我正在搜索。感谢您提供的信息。 - LefterisL

4

在评估了几种第三方语音识别选项之后,谷歌语音识别是最准确的。使用谷歌语音识别有两种基本方法。最简单的方法是启动一个意图并相应地处理结果:

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

    startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE );

在你的onActivityResults()方法中,你需要处理服务返回的匹配结果:

    /**
 * Handle the results from the recognition activity.
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    //Toast.makeText(this, "voice recog result: " + resultCode, Toast.LENGTH_LONG).show();
    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);
        // handleResults
        if (matches != null) {
            handleResults(matches); 
        }                    
    }     
}

第二种方法更复杂,但允许更好地处理在识别服务运行时可能发生的错误条件。使用此方法,您将创建自己的识别监听器和回调方法。例如:
开始侦听:
mSpeechRecognizer.startListening(mRecognizerIntent);

mRecognizerIntent是什么:

    mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(getBaseContext());
    mSpeechRecognizer.setRecognitionListener(mRecognitionListener);
    mRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    mRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    mRecognizerIntent.putExtra("calling_package", "com.you.package");

然后,创建您的监听器:

    private RecognitionListener mRecognitionListener = new RecognitionListener() {
            public void onBufferReceived(byte[] buffer) {
                    // TODO Auto-generated method stub
                    //Log.d(TAG, "onBufferReceived");
            }

            public void onError(int error) {
                    // TODO Auto-generated method stub
                    // here is where you handle the error...


            public void onEvent(int eventType, Bundle params) {
                    // TODO Auto-generated method stub
                    Log.d(TAG, "onEvent");
            }

            public void onPartialResults(Bundle partialResults) {
                    // TODO Auto-generated method stub
                    Log.d(TAG, "onPartialResults");
            }

            public void onReadyForSpeech(Bundle params) {
                    // TODO Auto-generated method stub
                    Log.d(TAG, "onReadyForSpeech");

            }

            public void onResults(Bundle results) {

                    Log.d(TAG, ">>> onResults");
                    //Toast.makeText(getBaseContext(), "got voice results!", Toast.LENGTH_SHORT);

                    ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
                    handleResults(matches);


            }

            public void onRmsChanged(float rmsdB) {
                    // TODO Auto-generated method stub
                    //Log.d(TAG, "onRmsChanged");
            }

            public void onBeginningOfSpeech() {
                    // TODO Auto-generated method stub
                    Log.d(TAG, "onBeginningOfSpeech");
            }

            public void onEndOfSpeech() {
                    // TODO Auto-generated method stub
                    Log.d(TAG, "onEndOfSpeech");

            }

};

你可以将你的handleResults()添加进去,以实现你想要的任何操作。

1

你也可以使用Google语音API。从Android中,它可以通过SpeechRecognizer 类引用访问。

这里有一个stackoverflow问题的链接,其中还包含一些Java演示代码:Java中的语音识别


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接