ストップボタンを押すまで音声認識で録音したい。これを行う方法を知っていますか?
解決策を試しましたが、休憩が長すぎない限り(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() {
//...
}