How to use SpeechRecognizer continuously without timeout. This is my code i am getting result on textview but this stops after listening few seconds. In my case i have to start until user don't stop it or it should stop after 15 to 20 minutes. if this is possible then please suggest me how to do. i want to increase timeout delay.
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);
}}