我想用语音识别来录音,直到你按下停止按钮。你知道有什么办法吗?
我尝试了一个解决方案,但它只在您不休息太久(4-5 秒)的情况下才有效。如果您在停止时按下 STOP 按钮,然后再次开始工作......
我该如何纠正?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myText = (TextView) findViewById(R.id.STT);
intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizer = SpeechRecognizer
.createSpeechRecognizer(getApplicationContext());
recognizer.setRecognitionListener(this);
}
public void start(View view) {
recognizer.startListening(intent);
}
public void stop(View view) {
recognizer.stopListening();
}
@Override
public void onResults(Bundle res) {
ArrayList<String> results = res
.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
myText.setText(results.get(0));
// ...
recognizer.startListening(intent);
}
@Override
public void onRmsChanged(float rmsdB) {
//...
}
@Override
public void onReadyForSpeech(Bundle params) {
//...
}
@Override
public void onPartialResults(Bundle data) {
//...
}
@Override
public void onEvent(int eventType, Bundle params) {
//...
}
@Override
public void onError(int error) {
//...
}
@Override
public void onEndOfSpeech() {
//...
}
@Override
public void onBufferReceived(byte[] buffer) {
//...
}
@Override
public void onBeginningOfSpeech() {
//...
}