Java中的开源语音识别软件

时间:2013-08-22 18:34:09

标签: java android speech-recognition

我最近一直在考虑开始基于语音识别的应用程序。 对特定任务的某些结果的意义。我想知道什么是最好的方法。我也想过PC或Android。我认为JAVA是我强大的编程语言。

我已经做了一些搜索,但我仍然不知道哪种方法可以解决这个问题。

有一个开放的软件为我做语音识别部分并在另一部分工作吗? 自己做整件事吗?如果可以在JAVA中使用吗?

任何信息都将不胜感激。

提前谢谢。

3 个答案:

答案 0 :(得分:6)

解决这个问题的最佳方法是使用现有的识别工具包以及随附的语言和声学模型。您可以训练模型以满足您的需求。

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

答案 1 :(得分:4)

在评估了多个第三方语音识别选项后,Google语音识别是迄今为止最准确的。使用Google语音识别时有两种基本方法。最简单的方法是启动一个Intent并相应地处理结果:

    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()来做你想做的事。

答案 2 :(得分:1)

您还可以使用Google Speech API。在Android中,可以通过SpeechRecognizer Class Reference

访问它

这是一个stackoverflow问题的链接,它还包含一些Java中的演示代码:Speech recognition in Java

相关问题