Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions app/src/main/java/com/termux/api/apis/SpeechToTextAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,6 @@ public void onBeginningOfSpeech() {
}).setNegativeButton("Cancel", null) // cancel button
.create().show();
}

Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Enter shell command");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 10);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
mSpeechRecognizer.startListening(recognizerIntent);
}

@Override
Expand All @@ -158,6 +150,22 @@ public void onDestroy() {
mSpeechRecognizer.destroy();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Logger.logDebug(LOG_TAG, "onStartCommand");

Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Enter shell command");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 10);
String language = intent.hasExtra("language") ? intent.getStringExtra("language") : "en-US";
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
mSpeechRecognizer.startListening(recognizerIntent);

return super.onStartCommand(intent, flags, startId);
}

@Override
protected void onHandleIntent(final Intent intent) {
Logger.logDebug(LOG_TAG, "onHandleIntent:\n" + IntentUtils.getIntentString(intent));
Expand Down