Java 中的开源语音识别软件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18388287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 01:06:56  来源:igfitidea点击:

Open Source Speech Recognition Software in Java

javaandroidspeech-recognition

提问by LefterisL

I've been thinking lately to start an application based on Speech recognition. Meaning on certain results to do specific tasks. I was wondering what is the best way to proceed. I'm thinking either for PC or Android also. I would consider JAVA as my strong programming language.

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

I've done some searching but still I don't know which is the best way to approach this.

我已经进行了一些搜索,但仍然不知道哪种方法是解决此问题的最佳方法。

Have an open software do the speech recognition part for me and work on the other part? Do the whole thing by myself? And if yes is it possible in JAVA?

有一个开放的软件为我做语音识别部分并在另一部分工作吗?整个事情一个人做?如果是,在 JAVA 中可能吗?

Any info will be appreciated.

任何信息将不胜感激。

Thank you in advance.

先感谢您。

采纳答案by Uku Loskit

The best way to approach this would be use an existing recognition toolkit and the language and acoustic models that come with it. You may train the models to fit your needs.

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

CMUSphinxis probably the best FOSS speech recognition toolkit out there. CMUSphinx also provides good Java integration and demo applications.

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

回答by Miterion

You can also use the Google Speech API. From Android it is accessible through the SpeechRecognizer Class Reference

您还可以使用 Google Speech API。从 Android 可以通过 SpeechRecognizer类参考访问

Here is a link to a stackoverflow question, which also contains some demo code in Java: Speech recognition in Java

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

回答by droideckar

After evaluating several 3rd party speech recognition options, Google voice recognition is by far the most accurate. There are two basic approaches when using Google voice recognition. The easiest is to launch an Intent and handle the results accordingly:

在评估了几个 3rd 方语音识别选项后,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 );

then in your onActivityResults(), you would handle the matches returned by the service:

然后在您的 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); 
        }                    
    }     
}

The second approach is more involved but allows for better handling of an error condition that can happen while the recognition service is running. Using this approach, you would create your own recognition listener and callback methods. For example:

第二种方法更复杂,但允许更好地处理识别服务运行时可能发生的错误情况。使用这种方法,您将创建自己的识别侦听器和回调方法。例如:

start listening:

开始聆听:

mSpeechRecognizer.startListening(mRecognizerIntent);

where 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");

then, create your listener:

然后,创建您的侦听器:

    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");

            }

};

you can add your handleResults() to do whatever you want.

你可以添加你的 handleResults() 来做任何你想做的事。