Java 安卓语音识别器如何使连续语音识别?

Java 安卓语音识别器如何使连续语音识别?,java,android,Java,Android,我正在尝试制作一个Android应用程序,它可以连续识别用户的语音并将其转换为文本 我已经有很长一段时间没能让语音识别器工作了。有没有办法让它一直听下去?应用程序不需要在后台运行。事实上,它根本不会在后台运行 public class MainActivity extends AppCompatActivity { private TextView resultTextView; private SpeechRecognizer speechRecognizer; @Override pro

我正在尝试制作一个Android应用程序,它可以连续识别用户的语音并将其转换为文本

我已经有很长一段时间没能让语音识别器工作了。有没有办法让它一直听下去?应用程序不需要在后台运行。事实上,它根本不会在后台运行

public class MainActivity extends AppCompatActivity {

private TextView resultTextView;
private SpeechRecognizer speechRecognizer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    resultTextView = (TextView) findViewById(R.id.resultsText);

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

    if(SpeechRecognizer.isRecognitionAvailable(this)){
        speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
        speechRecognizer.setRecognitionListener(new RecognitionListener() {
            @Override
            public void onReadyForSpeech(Bundle params) {}

            @Override
            public void onBeginningOfSpeech() {}

            @Override
            public void onRmsChanged(float rmsdB) {}

            @Override
            public void onBufferReceived(byte[] buffer) {}

            @Override
            public void onEndOfSpeech() {}

            @Override
            public void onError(int error) {}

            @Override
            public void onResults(Bundle bundle) {
                List<String> results = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
                resultTextView.setText(results.get(0)); 
            }

            @Override
            public void onPartialResults(Bundle partialResults) {}

            @Override
            public void onEvent(int eventType, Bundle params) {}
        });
    }

    speechRecognizer.startListening(intent);
}
}
public类MainActivity扩展了AppCompatActivity{
私有文本视图结果文本视图;
私人语音识别器语音识别器;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultTextView=(TextView)findViewById(R.id.resultsText);
意向意向=新意向(识别意向、行动、识别言语);
intent.putExtra(RecognizerIntent.EXTRA语言模型,RecognizerIntent.LANGUAGE模型自由形式);
if(SpeechRecognizer.isRecognitionAvailable(this)){
speechRecognizer=speechRecognizer.createSpeechRecognizer(this);
setRecognitionListener(新的RecognitionListener(){
@凌驾
public void onReadyForSpeech(Bundle参数){}
@凌驾
public void onBeginingOfspeech(){}
@凌驾
公共无效onRmsChanged(浮动rmsdB){}
@凌驾
已接收到公用无效onBufferReceived(字节[]缓冲区){}
@凌驾
public void onEndOfSpeech(){}
@凌驾
public void onError(int error){}
@凌驾
公共void onResults(Bundle){
列表结果=bundle.getStringArrayList(SpeechRecognitor.results\u RECOGNITION);
resultTextView.setText(results.get(0));
}
@凌驾
public void onPartialResults(Bundle partialResults){}
@凌驾
public void onEvent(int eventType,Bundle参数){}
});
}
语音识别器。吃惊倾听(意图);
}
}

如果您正在使用
意图
来使用语音识别器,您将受到应用程序/系统服务的摆布,而该服务实际上正在改变语音到文本的行为。如果你想控制收听时间,你可能需要看看各种云供应商。@morrisonchange有什么好的建议吗?我需要相对快速的准确结果。离线也很好,但我不确定云供应商是否有可能。如果你使用
意图
来使用语音识别器,你将受到应用程序/系统服务的摆布,而该应用程序/系统服务实际上正在改变语音对文本的行为。如果你想控制收听时间,你可能需要看看各种云供应商。@morrisonchange有什么好的建议吗?我需要相对快速的准确结果。离线也很好,但我不确定云供应商是否可能做到这一点。