I am currently busy with speech recognition, and I want the speech recognizer to listen to me constantly, forever. The purpose of the application is that it waits for a response to a specific keyword: when the user speaks this keyword, the service becomes ready to accept the user's voice commands. After researching, I found that we can set aside the time that the resolver is listening. By these constants:
By the way, the recognition service by default listens for about 10 seconds. (Google api)
String EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS The amount of time that it should take after we stop hearing speech to consider the input complete. String EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS The minimum length of an utterance. String EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS The amount of time that it should take after we stop hearing speech to consider the input possibly complete.
http://java.llp2.dcc.ufmg.br/apiminer/docs/reference/android/speech/RecognizerIntent.html
These are additional classes of the bundle class.
The problem is that when I use these constants in my code, it does not work.
Here is my code:
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 5000); intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 5000); intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 5000);
The activator still listens to me for about 10 seconds, although I wrote 5000 ms, as you can see.
Can you come up with a problem? Maybe I donโt know how to use additional functions, or maybe about permissions, and maybe it skips my code, or I should add other codes.
Any help would be assigned.
Edit: Here is my full code:
VoiceRecognitionActivity.java
public class VoiceRecognitionActivity extends Activity implements TextToSpeech.OnInitListener { private static final int REQUEST_CODE = 1234; private Button mTalkButton; private ListView wordsList; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_voice_recognition); mTalkButton = (Button) findViewById(R.id.talk_button); wordsList = (ListView) findViewById(R.id.listView1);
}
TTSUtils.java
The public class TTSUtils implements TextToSpeech.OnInitListener {
private TextToSpeech mTts; private static TTSUtils mInstance; private Context mContext; public static TTSUtils getInstance(Context c) { if (mInstance == null) { mInstance = new TTSUtils(c); } return mInstance; } private TTSUtils(Context c) { mContext = c; mTts = new TextToSpeech(mContext, this); mInstance = this; } @Override public void onInit(int status) {
}
SettingsActivity.java
public class SettingsActivity extends PreferenceActivity {
private static final boolean ALWAYS_SIMPLE_PREFS = false; @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setupSimplePreferencesScreen(); } private void setupSimplePreferencesScreen() { if (!isSimplePreferences(this)) { return; }
}