From d06a08eb8134e95fe362ee48ee5385b9aa7850cc Mon Sep 17 00:00:00 2001 From: FongMi Date: Mon, 28 Nov 2022 17:34:50 +0800 Subject: [PATCH] Fix speech crash --- .../com/fongmi/android/tv/ui/custom/CustomMic.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomMic.java b/app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomMic.java index f421c826e..a5c0c91c1 100644 --- a/app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomMic.java +++ b/app/src/leanback/java/com/fongmi/android/tv/ui/custom/CustomMic.java @@ -66,12 +66,19 @@ public class CustomMic extends AppCompatImageView { else launcher.launch(Manifest.permission.RECORD_AUDIO); } + private void startListening() { + try { + Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); + intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); + recognizer.startListening(intent); + } catch (Exception ignored) { + } + } + public void start() { - Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); - intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); setColorFilter(MDColor.RED_500, PorterDuff.Mode.SRC_IN); - recognizer.startListening(intent); startAnimation(flicker); + startListening(); setListen(true); }