diff --git a/app/src/main/java/com/termux/api/apis/SpeechToTextAPI.java b/app/src/main/java/com/termux/api/apis/SpeechToTextAPI.java index c33d7a31a..2ca9baa46 100644 --- a/app/src/main/java/com/termux/api/apis/SpeechToTextAPI.java +++ b/app/src/main/java/com/termux/api/apis/SpeechToTextAPI.java @@ -19,11 +19,13 @@ import java.io.PrintWriter; import java.util.List; +import java.util.Locale; import java.util.concurrent.LinkedBlockingQueue; public class SpeechToTextAPI { private static final String LOG_TAG = "SpeechToTextAPI"; + private static String language; public static class SpeechToTextService extends IntentService { @@ -145,7 +147,7 @@ public void onBeginningOfSpeech() { 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_LANGUAGE, language); recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); mSpeechRecognizer.startListening(recognizerIntent); } @@ -182,6 +184,16 @@ public void writeResult(PrintWriter out) throws Exception { public static void onReceive(final Context context, Intent intent) { Logger.logDebug(LOG_TAG, "onReceive"); + if (intent.hasExtra("language")) { + language = intent.getStringExtra("language"); + //Toast.makeText(context,"using language [from parameter]: " + language, Toast.LENGTH_SHORT).show(); + Logger.logDebug(LOG_TAG, "using language [from parameter]: " + language); + } else { + language = String.valueOf(Locale.getDefault()); + //Toast.makeText(context,"using language [from locale default]: " + language, Toast.LENGTH_SHORT).show(); + Logger.logDebug(LOG_TAG, "using language [from locale default]: " + language); + } + context.startService(new Intent(context, SpeechToTextService.class).putExtras(intent.getExtras())); }