如何在没有超时的情况下连续使用SpeechRecognizer。这是我的代码我在textview上得到了结果,但是在听完几秒后停止了。在我的情况下,我必须开始,直到用户不停止它或它应该在15至20分钟后停止。如果这是可能的,那么请建议我该怎么做。我想增加超时延迟。
public class VoiceService extends Service {
String result;
private SpeechRecognizer sr;
class listener implements RecognitionListener {
listener() {
}
public void onReadyForSpeech(Bundle params) {
}
public void onBeginningOfSpeech() {Toast.makeText(VoiceService.this, "Listening", Toast.LENGTH_SHORT).show();}
public void onRmsChanged(float rmsdB) {
}
public void onBufferReceived(byte[] buffer) {
}
public void onEndOfSpeech() {
Toast.makeText(VoiceService.this, "Stopped", Toast.LENGTH_SHORT).show();
}
public void onError(int error) {
}
public void onResults(Bundle results) {
ArrayList<String> matches =
results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if (matches != null){
FragmentTwo.textViewresult.setText(matches.get(0));}
}
public void onPartialResults(Bundle partialResults) {
}
public void onEvent(int eventType, Bundle params) {
}
}
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
public void onCreate() {
super.onCreate();
Toast.makeText(this, "Service Started",
Toast.LENGTH_SHORT).show();
AudioManager amanager = (AudioManager)
getSystemService("audio");
amanager.setStreamMute(3, true);
amanager.setStreamMute(1, true);
onClickk();
}
public void onDestroy() {
super.onDestroy();
if (this.sr != null) {
this.sr.destroy();
}
Toast.makeText(this, "Voice Service Stopped", Toast.LENGTH_SHORT).show();
}
public void onClickk() {
if (this.sr != null) {
this.sr.destroy();
}
this.sr = SpeechRecognizer.createSpeechRecognizer(this);
this.sr.setRecognitionListener(new listener());
Intent intent = new Intent("android.speech.action.RECOGNIZE_SPEECH");
intent.putExtra("android.speech.extra.LANGUAGE_MODEL", "free_form");
intent.putExtra("android.speech.extra.MAX_RESULTS", 1);
this.sr.startListening(intent);
}}